Header menu logo Euclid

Matrix Type

An immutable 4x4 transformation matrix. The matrix is represented in the following column-vector syntax form: M11 M21 M31 X41 M12 M22 M32 Y42 M13 M23 M33 Z43 M14 M24 M34 M44 Where X41, Y42 and Z43 refer to the translation part of the matrix. Note: Never use the struct default constructor Matrix() as it will create an invalid zero Matrix. Use Matrix.create or Matrix.createUnchecked instead.

Record fields

Record Field Description

M11

Full Usage: M11

Field type: float
Field type: float

M12

Full Usage: M12

Field type: float
Field type: float

M13

Full Usage: M13

Field type: float
Field type: float

M14

Full Usage: M14

Field type: float
Field type: float

M21

Full Usage: M21

Field type: float
Field type: float

M22

Full Usage: M22

Field type: float
Field type: float

M23

Full Usage: M23

Field type: float
Field type: float

M24

Full Usage: M24

Field type: float
Field type: float

M31

Full Usage: M31

Field type: float
Field type: float

M32

Full Usage: M32

Field type: float
Field type: float

M33

Full Usage: M33

Field type: float
Field type: float

M34

Full Usage: M34

Field type: float
Field type: float

M44

Full Usage: M44

Field type: float
Field type: float

X41

Full Usage: X41

Field type: float
Field type: float

Y42

Full Usage: Y42

Field type: float
Field type: float

Z43

Full Usage: Z43

Field type: float
Field type: float

Constructors

Constructor Description

Matrix(m11, m21, m31, x41, m12, m22, m32, y42, m13, m23, m33, z43, m14, m24, m34, m44)

Full Usage: Matrix(m11, m21, m31, x41, m12, m22, m32, y42, m13, m23, m33, z43, m14, m24, m34, m44)

Parameters:
    m11 : float
    m21 : float
    m31 : float
    x41 : float
    m12 : float
    m22 : float
    m32 : float
    y42 : float
    m13 : float
    m23 : float
    m33 : float
    z43 : float
    m14 : float
    m24 : float
    m34 : float
    m44 : float

Returns: Matrix

Create a 4x4 Transformation Matrix. This Constructor takes arguments in row-major order, The matrix is represented in the following column-vector syntax form: M11 M21 M31 X41 M12 M22 M32 Y42 M13 M23 M33 Z43 M14 M24 M34 M44 Where X41, Y42 and Z43 refer to the translation part of the matrix.

m11 : float
m21 : float
m31 : float
x41 : float
m12 : float
m22 : float
m32 : float
y42 : float
m13 : float
m23 : float
m33 : float
z43 : float
m14 : float
m24 : float
m34 : float
m44 : float
Returns: Matrix

Instance members

Instance member Description

this.ColumnVector1

Full Usage: this.ColumnVector1

Returns: Vec

Returns the first column vector. M11, M12 and M13

Returns: Vec

this.ColumnVector2

Full Usage: this.ColumnVector2

Returns: Vec

Returns the second column vector. M21, M22 and M23

Returns: Vec

this.ColumnVector3

Full Usage: this.ColumnVector3

Returns: Vec

Returns the third column vector. M31, M32 and M33

Returns: Vec

this.Determinant

Full Usage: this.Determinant

Returns: float

The determinant of the Matrix. The Determinant describes the signed volume that a unit cube will have after the matrix was applied.

Returns: float

this.Inverse

Full Usage: this.Inverse

Returns: Matrix

Inverts the matrix. If the determinant is zero the Matrix cannot be inverted. An Exception is raised.

Returns: Matrix

this.IsAffine

Full Usage: this.IsAffine

Returns: bool

Checks if the Matrix is an affine transformation. That means it does not do any projection. The fields m.M14, m.M24 and m.M34 must be 0.0 and m.M44 must be 1.0 or very close to it. Using an approximate tolerance of 1e-6.

Returns: bool

this.IsIdentity

Full Usage: this.IsIdentity

Returns: bool

Checks if the Matrix is an identity matrix in the form of: 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 Using an approximate tolerance of 1e-6.

Returns: bool

this.IsMirroring

Full Usage: this.IsMirroring

Returns: bool

Returns if the Matrix is mirroring or reflection. It might also be rotating, translating or scaling, but not projecting. It must be affine and the determinate of the 3x3 part must be negative. Same as m.IsReflecting.

Returns: bool

this.IsOnlyTranslating

Full Usage: this.IsOnlyTranslating

Returns: bool

Returns true if the Matrix is only translating. It might not be rotating, scaling, reflecting, or projecting.

Returns: bool

this.IsOrthogonal

Full Usage: this.IsOrthogonal

Returns: bool

Returns if the Matrix is orthogonal. It might also be mirroring or scaling, but not shearing or projecting. It must be affine and the dot products of the three column vectors must be zero.

Returns: bool

this.IsProjecting

Full Usage: this.IsProjecting

Returns: bool

Checks if the Matrix is an affine transformation. That means it does not do any projection. The fields m.M14, m.M24 and m.M34 must be 0.0 and m.M44 must be 1.0 or very close to it. Using an approximate tolerance of 1e-6.

Returns: bool

this.IsReflecting

Full Usage: this.IsReflecting

Returns: bool

Returns if the Matrix is mirroring or reflection. It might also be rotating, translating or scaling, but not projecting. It must be affine and the determinate of the 3x3 part must be negative. Same as m.IsMirroring.

Returns: bool

this.IsScaling

Full Usage: this.IsScaling

Returns: bool

Returns if the Matrix is scaling. It might also be rotating, translating or reflecting, but not projecting. It must be affine and the 3 column vector must have a length other than one.

Returns: bool

this.IsTranslating

Full Usage: this.IsTranslating

Returns: bool

Returns true if the Matrix is translating. It might also be rotating, scaling and reflecting, but not projecting.

Returns: bool

this.ToArrayByColumns

Full Usage: this.ToArrayByColumns

Returns: float[]

Returns the 16 elements column-major order: [| M11 M12 M13 M14 M21 M22 M23 M24 M31 M32 M33 M34 X41 Y42 Z43 M44 |] Where X41, Y42 and Z43 refer to the translation part of the matrix.

Returns: float[]

this.ToArrayByRows

Full Usage: this.ToArrayByRows

Returns: float[]

Returns the 16 elements in row-major order: [| M11 M21 M31 X41 M12 M22 M32 Y42 M13 M23 M33 Z43 M14 M24 M34 M44 |] Where X41, Y42 and Z43 refer to the translation part of the matrix.

Returns: float[]

this.Translation

Full Usage: this.Translation

Returns: Vec

Returns the translation or forth column vector. X41, Y42 and Z43

Returns: Vec

Static members

Static member Description

p *** m

Full Usage: p *** m

Parameters:
Returns: Pnt
Modifiers: inline

Multiplies (or applies) a Matrix to a 3D point (with an implicit 1 in the 4th dimension, so that it also works correctly for projections.)

p : Pnt
m : Matrix
Returns: Pnt

v *** m

Full Usage: v *** m

Parameters:
Returns: Vec
Modifiers: inline

Multiplies a Matrix with a 3D vector Since a 3D vector represents a direction or an offset in space, but not a location, the implicit the 4th dimension is 0.0 so that all translations are ignored. (Homogeneous Vector)

v : UnitVec
m : Matrix
Returns: Vec

v *** m

Full Usage: v *** m

Parameters:
Returns: Vec
Modifiers: inline

Multiplies (or applies) a Matrix to a 3D vector Since a 3D vector represents a direction or an offset in space, but not a location, the implicit the 4th dimension is 0.0 so that all translations are ignored. (Homogeneous Vector)

v : Vec
m : Matrix
Returns: Vec

matrixA *** matrixB

Full Usage: matrixA *** matrixB

Parameters:
Returns: Matrix
Modifiers: inline

Multiplies matrixA with matrixB. The resulting transformation will first do matrixA and then matrixB.

matrixA : Matrix
matrixB : Matrix
Returns: Matrix

Matrix.addTranslation v m

Full Usage: Matrix.addTranslation v m

Parameters:
Returns: Matrix

Add a vector translation to an existing matrix.

v : Vec
m : Matrix
Returns: Matrix

Matrix.addTranslationXYZ x y z m

Full Usage: Matrix.addTranslationXYZ x y z m

Parameters:
    x : float
    y : float
    z : float
    m : Matrix

Returns: Matrix

Add a X, Y and Z translation to an existing matrix.

x : float
y : float
z : float
m : Matrix
Returns: Matrix

Matrix.createFromColumMajorArray xs

Full Usage: Matrix.createFromColumMajorArray xs

Parameters:
    xs : float[]

Returns: Matrix

Creates a matrix from array of 16 elements in Column Major order: [| M11 M12 M13 M14 M21 M22 M23 M24 M31 M32 M33 M34 X41 Y42 Z43 M44 |] Where X41, Y42 and Z43 refer to the translation part of the matrix.

xs : float[]
Returns: Matrix

Matrix.createFromQuaternion quaternion

Full Usage: Matrix.createFromQuaternion quaternion

Parameters:
Returns: Matrix

Create Matrix from Quaternion.

quaternion : Quaternion
Returns: Matrix

Matrix.createFromRowMajorArray xs

Full Usage: Matrix.createFromRowMajorArray xs

Parameters:
    xs : float[]

Returns: Matrix

Creates a matrix from array of 16 elements in Row Major order: [| M11 M21 M31 X41 M12 M22 M32 Y42 M13 M23 M33 Z43 M14 M24 M34 M44 |] Where X41, Y42 and Z43 refer to the translation part of the matrix.

xs : float[]
Returns: Matrix

Matrix.createMirror p

Full Usage: Matrix.createMirror p

Parameters:
Returns: Matrix

Creates a Matrix to mirror on a Plane.

p : PPlane
Returns: Matrix

Matrix.createPerspective (width, height, nearPlaneDistance, farPlaneDistance)

Full Usage: Matrix.createPerspective (width, height, nearPlaneDistance, farPlaneDistance)

Parameters:
    width : float - Width of the view volume at the near view plane.
    height : float - Height of the view volume at the near view plane.
    nearPlaneDistance : float - Distance to the near view plane.
    farPlaneDistance : float - Distance to the far view plane.

Returns: Matrix The perspective projection matrix.

Creates a perspective projection matrix from the given view volume dimensions.

width : float

Width of the view volume at the near view plane.

height : float

Height of the view volume at the near view plane.

nearPlaneDistance : float

Distance to the near view plane.

farPlaneDistance : float

Distance to the far view plane.

Returns: Matrix

The perspective projection matrix.

Matrix.createPlaneToPlane (fromPlane, toPlane)

Full Usage: Matrix.createPlaneToPlane (fromPlane, toPlane)

Parameters:
Returns: Matrix

Creates a Matrix to transform from one Plane or Coordinate System to another Plane.

fromPlane : PPlane
toPlane : PPlane
Returns: Matrix

Matrix.createRotationAxis (axis, angleDegrees)

Full Usage: Matrix.createRotationAxis (axis, angleDegrees)

Parameters:
    axis : Vec
    angleDegrees : float

Returns: Matrix

Creates a rotation around an axis transformation matrix. axis — Rotation axis, a vector of any length but 0.0 . angleDegrees — Rotation angle in Degrees. Returns a positive rotation will be so clockwise looking in the direction of the axis vector.

axis : Vec
angleDegrees : float
Returns: Matrix

Matrix.createRotationAxis (axis, angleDegrees)

Full Usage: Matrix.createRotationAxis (axis, angleDegrees)

Parameters:
    axis : UnitVec
    angleDegrees : float

Returns: Matrix

Creates a rotation around an axis transformation matrix. axis — Rotation axis, as unit-vector. angleDegrees — Rotation angle in Degrees. Returns a positive rotation will be so clockwise looking in the direction of the axis vector.

axis : UnitVec
angleDegrees : float
Returns: Matrix

Matrix.createRotationAxisCenter (axis, cen, angleDegrees)

Full Usage: Matrix.createRotationAxisCenter (axis, cen, angleDegrees)

Parameters:
Returns: Matrix

Creates a rotation matrix around an axis at a given center point. axis — Rotation axis, a unit-vector. cen — The center point for the rotation. angleDegrees — Rotation angle in Degrees. Returns a positive rotation will be so clockwise looking in the direction of the axis vector.

axis : UnitVec
cen : Pnt
angleDegrees : float
Returns: Matrix

Matrix.createRotationAxisCenter (axis, cen, angleDegrees)

Full Usage: Matrix.createRotationAxisCenter (axis, cen, angleDegrees)

Parameters:
    axis : Vec
    cen : Pnt
    angleDegrees : float

Returns: Matrix

Creates a rotation matrix around an axis at a given center point. axis — Rotation axis, a vector of any length but 0.0 cen — The center point for the rotation. angleDegrees — Rotation angle in Degrees. Returns a positive rotation will be so clockwise looking in the direction of the axis vector.

axis : Vec
cen : Pnt
angleDegrees : float
Returns: Matrix

Matrix.createRotationX angleDegrees

Full Usage: Matrix.createRotationX angleDegrees

Parameters:
    angleDegrees : float

Returns: Matrix

Creates a rotation transformation matrix around the X-axis by angle in Degrees (not Radians). angleDegrees — Rotation angle in Degrees. A positive rotation will be from Y towards Z-axis, so counter-clockwise looking onto Y-X Plane. The resulting matrix will be: 1 0 0 0 0 cos(θ) -sin(θ) 0 0 sin(θ) cos(θ) 0 0 0 0 1

angleDegrees : float
Returns: Matrix

Matrix.createRotationY angleDegrees

Full Usage: Matrix.createRotationY angleDegrees

Parameters:
    angleDegrees : float

Returns: Matrix

Creates a rotation transformation matrix around the Y-axis by angle in Degrees (not Radians). angleDegrees — Rotation angle in Degrees. A positive rotation will be from Z towards X-axis, so counter-clockwise looking onto Z-X Plane. The resulting matrix will be: cos(θ) 0 sin(θ) 0 0 1 0 0 -sin(θ) 0 cos(θ) 0 0 0 0 1

angleDegrees : float
Returns: Matrix

Matrix.createRotationZ angleDegrees

Full Usage: Matrix.createRotationZ angleDegrees

Parameters:
    angleDegrees : float

Returns: Matrix

Creates a rotation transformation matrix around the Z-axis by angle in Degrees (not Radians). angleDegrees — Rotation angle in Degrees. Returns a positive rotation will be from X toward Y-axis, so counter-clockwise looking onto X-Y plane. The resulting matrix will be: cos(θ) -sin(θ) 0 0 sin(θ) cos(θ) 0 0 0 0 1 0 0 0 0 1

angleDegrees : float
Returns: Matrix

Matrix.createScale (x, y, z)

Full Usage: Matrix.createScale (x, y, z)

Parameters:
    x : float
    y : float
    z : float

Returns: Matrix

Creates a scale transformation matrix: x - the amount to scale in the X-axis. y - the amount to scale in the Y-axis. z - the amount to scale in the Z-axis. The resulting matrix will be: x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1

x : float
y : float
z : float
Returns: Matrix

Matrix.createShear (xy, xz, yx, yz, zx, zy)

Full Usage: Matrix.createShear (xy, xz, yx, yz, zx, zy)

Parameters:
    xy : float
    xz : float
    yx : float
    yz : float
    zx : float
    zy : float

Returns: Matrix

Creates a shear transformation matrix: xy - the amount to shear a X unit-vector a long Y-axis. xz - the amount to shear a X unit-vector a long Z-axis. yx - the amount to shear a Y unit-vector a long X-axis. yz - the amount to shear a Y unit-vector a long Z-axis. zx - the amount to shear a Z unit-vector a long X-axis. zy - the amount to shear a Z unit-vector a long Y-axis. The resulting matrix will be: 1, yx, zx, 0, xy, 1, zy, 0, xz, yz, 1, 0, 0, 0, 0, 1

xy : float
xz : float
yx : float
yz : float
zx : float
zy : float
Returns: Matrix

Matrix.createToPlane p

Full Usage: Matrix.createToPlane p

Parameters:
Returns: Matrix

Creates a Matrix to transform from World plane or Coordinate System to given Plane. Also called Change of Basis.

p : PPlane
Returns: Matrix

Matrix.createTranslation v

Full Usage: Matrix.createTranslation v

Parameters:
Returns: Matrix

Creates a translation matrix: Vec - the vector by which to translate. The resulting matrix will be: 1 0 0 v.X 0 1 0 v.Y 0 0 1 v.Z 0 0 0 1

v : Vec
Returns: Matrix

Matrix.createTranslation (x, y, z)

Full Usage: Matrix.createTranslation (x, y, z)

Parameters:
    x : float
    y : float
    z : float

Returns: Matrix

Creates a translation matrix: x - the amount to translate in the X-axis. y - the amount to translate in the Y-axis. z - the amount to translate in the Z-axis. The resulting matrix will be: 1 0 0 x 0 1 0 y 0 0 1 z 0 0 0 1

x : float
y : float
z : float
Returns: Matrix

Matrix.createVecToVec (vecFrom, vecTo)

Full Usage: Matrix.createVecToVec (vecFrom, vecTo)

Parameters:
Returns: Matrix

Creates a rotation from one vectors direction to another vectors direction. If the tips of the two vectors unitized are closer than 1e-12 the identity matrix is returned. If the tips of the two vectors are almost exactly opposite, deviating less than 1e-6 from line (unitized), there is no valid unique 180 degree rotation that can be found, so an exception is raised.

vecFrom : Vec
vecTo : Vec
Returns: Matrix

Matrix.createVecToVec (vecFrom, vecTo)

Full Usage: Matrix.createVecToVec (vecFrom, vecTo)

Parameters:
Returns: Matrix

Creates a rotation from one vectors direction to another vectors direction. If the tips of the two vectors are closer than 1e-12 the identity matrix is returned. If the tips of the two vectors are almost exactly opposite, deviating less than 1e-6 from line, there is no valid unique 180 degree rotation that can be found, so an exception is raised.

vecFrom : UnitVec
vecTo : UnitVec
Returns: Matrix

Matrix.determinant m

Full Usage: Matrix.determinant m

Parameters:
Returns: float
Modifiers: inline

If the determinant of the Matrix. The determinant describes the volume that a unit cube will have have the matrix was applied.

m : Matrix
Returns: float

Matrix.equals tol a b

Full Usage: Matrix.equals tol a b

Parameters:
Returns: bool

Checks if two matrices are equal within tolerance. By comparing the fields M11 to M44 each with the given tolerance. Use a tolerance of 0.0 to check for an exact match.

tol : float
a : Matrix
b : Matrix
Returns: bool

Matrix.identity

Full Usage: Matrix.identity

Returns: Matrix

Returns the identity matrix: 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1

Returns: Matrix

Matrix.inverse m

Full Usage: Matrix.inverse m

Parameters:
Returns: Matrix
Modifiers: inline

Inverses the matrix. If the determinant is zero the Matrix cannot be inverted. An exception is raised.

m : Matrix
Returns: Matrix

Matrix.multiply (matrixA, matrixB)

Full Usage: Matrix.multiply (matrixA, matrixB)

Parameters:
Returns: Matrix

Multiplies matrixA with matrixB. The resulting transformation will first do matrixA and then matrixB.

matrixA : Matrix
matrixB : Matrix
Returns: Matrix

Matrix.toArrayByColumns m

Full Usage: Matrix.toArrayByColumns m

Parameters:
Returns: float[]
Modifiers: inline

Returns the 16 elements column-major order: [| M11 M12 M13 M14 M21 M22 M23 M24 M31 M32 M33 M34 X41 Y42 Z43 M44 |] Where X41, Y42 and Z43 refer to the translation part of the matrix.

m : Matrix
Returns: float[]

Matrix.toArrayByRows m

Full Usage: Matrix.toArrayByRows m

Parameters:
Returns: float[]
Modifiers: inline

Returns the 16 elements in row-major order: [| M11 M21 M31 X41 M12 M22 M32 Y42 M13 M23 M33 Z43 M14 M24 M34 M44 |] Where X41, Y42 and Z43 refer to the translation part of the matrix.

m : Matrix
Returns: float[]

Matrix.transpose m

Full Usage: Matrix.transpose m

Parameters:
Returns: Matrix

Transposes the Matrix.

m : Matrix
Returns: Matrix

Type something to start searching.