ianmackenzie / elm-geometry-linear-algebra-interop / Geometry.Interop.LinearAlgebra.Vector3d

Conversion and transformation functions for Vector3d.

toVec3 : Vector3d units coordinates -> Math.Vector3.Vec3

Convert a Vector3d to a Vec3.

Vector3d.toVec3 (Vector3d.meters 2 1 3)
--> Vector3.vec3 2 1 3

toVec4 : Vector3d units coordinates -> Math.Vector4.Vec4

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.meters 2 1 3)
--> vec4 2 1 3 0

fromVec3 : Math.Vector3.Vec3 -> Vector3d units coordinates

Convert a Vec3 to a Vector3d.

Vector3d.fromVec3 (Vector3.vec3 2 1 3)
--> Vector3d.unsafe { x = 2, y = 1, z = 3 }

transformBy : Math.Matrix4.Mat4 -> Vector3d units1 coordinates1 -> Vector3d units2 coordinates2

Transform a Vector3d by a Mat4; note that

vector
    |> Vector3d.transformBy matrix

is similar to but not in general equivalent to

vector
    |> Vector3d.toVec3
    |> Matrix4.transform matrix
    |> Vector3d.fromVec3

since 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.meters 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.meters -1 2 3