Conversion and transformation functions for Vector3d.
Convert a Vector3d to a Vec4. The resulting Vec4 will have a W
component of 0 so that it is not affected by translation
when performing matrix transformations.
Vector3d.toVec4 (Vector3d.fromComponents ( 2, 1, 3 ))
--> vec4 2 1 3 0Convert a Vec3 to a Vector3d.
Vector3d.fromVec3 (Vector3.vec3 2 1 3)
--> Vector3d ( 2, 1, 3 )Transform a Vector3d by a Mat4; note that
vector
|> Vector3d.transformBy matrixis similar to but not in general equivalent to
vector
|> Vector3d.toVec3
|> Matrix4.transform matrix
|> Vector3d.fromVec3since Matrix4.transform implicitly assumes that the given argument represents
a point, not a vector, and therefore applies translation to it. Transforming a
vector by a 4x4 matrix should in fact ignore any translation component of the
matrix, which this function does. For example:
vector =
Vector3d.fromComponents ( 2, 1, 3 )
-- 90 degree rotation around the Z axis,
-- followed by a translation
matrix =
Matrix4.makeTranslate3 5 5 5
|> Matrix4.rotate (degrees 90) Vector3.k
Vector3d.transformBy matrix vector
--> Vector3d.fromComponents ( -1, 2, 3 )
Convert a
Vector3dto aVec3.