Matrix

class Matrix()

Object representing the 4x4 Matrix. More information can be found here.

Constructors

Matrix.constructor()
Matrix(): Matrix

Creates a new matrix set to the identity matrix.

Returns: Matrix

Properties

Matrix.m

Methods

Matrix.assign()
assign(matrix: Matrix): this

Sets the value of this matrix to another.

Parameters

matrix: Matrix

the matrix whose values will be set.

Returns: this

This matrix object.
Matrix.copy()
copy(): Matrix

Creates a copy of this matrix.

Returns: Matrix

Copy of this matrix.
Matrix.equals()
equals(other: Matrix): boolean

Strictly compares this matrix with another.

Parameters

other: Matrix

Matrix to compare with.

Returns: boolean

True if the values of this matrix equal those of the other.
Matrix.equalsWithTolerance()
equalsWithTolerance(other: Matrix, tolerance: number): boolean

Compares this matrix with another using a tolerance.

Parameters

other: Matrix

Matrix to compare with.

tolerance: number

Tolerance to be used in the comparison.

Returns: boolean

True if the values of this matrix equal those of the other.
Matrix.inverseAndDeterminant()
inverseAndDeterminant(): [(None | Matrix), number]

Computes the determinant and inverse of a matrix, if possible.

Returns: [(None | Matrix), number]

An array containing the inverse (or null if not invertible) followed by the determinant
Matrix.isIdentity()
isIdentity(): boolean

Returns: boolean

Matrix.loadIdentity()
loadIdentity(): this

Sets the matrix to the identity matrix.

Returns: this

This matrix object.
Matrix.multiplyByScalar()
multiplyByScalar(scalar: number): this

Multiply the matrix by given scalar.

Parameters

scalar: number

Scalar to multiply the matrix with.

Returns: this

This matrix object.
Matrix.normalMatrix()
normalMatrix(): (None | Matrix)

Returns: (None | Matrix)

the version of this matrix suitable for applying to normals, i.e. the inverse transpose of the upper-left 3x3 submatrix.
Matrix.setScaleComponent()
setScaleComponent(x: number, y: number, z: number): this

Sets the scale components of this matrix.

Parameters

x: number

X scale value.

y: number

Y scale value.

z: number

Z scale value.

Returns: this

This matrix object.
Matrix.setTranslationComponent()
setTranslationComponent(x: number, y: number, z: number): this

Sets the translation components of this matrix.

Parameters

x: number

X translation value.

y: number

Y translation value.

z: number

Z translation value.

Returns: this

This matrix object.
Matrix.toJson()
toJson(): number[]

Creates an object ready for JSON serialization.

Returns: number[]

The prepared object.
Matrix.transform()
transform(point: Point3, result: Point3): Point3

Transforms a point according to this matrix. The source and destination points are allowed to be the same object.

Parameters

point: Point3

The point to be transformed.

result: Point3

A Point3 which can hold the result of the transformation.

Returns: Point3

A new point if result is undefined, result otherwise.
Matrix.transform4()
transform4(point: Point4, result: Point4): Point4

Transforms a point according to this matrix. The source and destination points are allowed to be the same object.

Parameters

point: Point4

The point to be transformed.

result: Point4

A Point3 which can hold the result of the transformation.

Returns: Point4

A new point if result is undefined, result otherwise.
Matrix.transformArray()
transformArray(inPoints: Point3[], outPoints: Point3[]): void

Transforms an array of points according to this matrix.

Parameters

inPoints: Point3[]

an array of points to be transformed.

outPoints: Point3[]

an array that will be populated with transformed points. Note that the results will be pushed onto the end of the array.

Returns: void

Matrix.transformBox()
transformBox(inBox: Box): Box

Parameters

inBox: Box

Returns: Box

Matrix.transpose()
transpose(): this

Sets this matrix equal to its transpose.

Returns: this

This matrix object.
Matrix.upperLeft3x3Determinant()
upperLeft3x3Determinant(): number

Computes the determinant of the upper-left 3x3 subsection of this matrix.

Returns: number

static Matrix.createFromArray()

static

createFromArray(arr: number[]): Matrix

Creates a matrix from an array of numbers.

Parameters

arr: number[]

16 element array of numbers.

Returns: Matrix

New matrix with elements set to the values of the array parameter. Array elements will be in column-major order.
static Matrix.createFromBasis()

static

createFromBasis(xAxis: Point3, yAxis: Point3, zAxis: Point3): Matrix

Creates a matrix from three [[Point3]]s, which will be used as the columns of the matrix.

Parameters

xAxis: Point3

The first column.

yAxis: Point3

The second column.

zAxis: Point3

The third column.

Returns: Matrix

static Matrix.createFromOffAxisRotation()

static

createFromOffAxisRotation(axis: Point3, degrees: number): Matrix

Creates a rotation matrix from an arbitrary axis.

Parameters

axis: Point3

Axis to rotate about.

degrees: number

Amount of degrees to rotate about the provided axis.

Returns: Matrix

Rotation matrix which represents the rotation about the supplied axis.
static Matrix.fromJson()

static

fromJson(obj: unknown): Matrix

Creates a new [[Matrix]] from an object given by [[toJson]].

Parameters

obj: unknown

Returns: Matrix

The prepared object.
static Matrix.inverse()

static

inverse(matrix: Matrix): (None | Matrix)

Computes the inverse of a matrix if possible.

Parameters

matrix: Matrix

Matrix whose inverse will be computed.

Returns: (None | Matrix)

Matrix set to the inverse of the supplied matrix.
static Matrix.multiply()

static

multiply(m1: Matrix, m2: Matrix): Matrix

Multiplies two matrices.

(p’ = ABp <=> p’ = multiply(B, A).transform(p))

Parameters

m1: Matrix

The first matrix.

m2: Matrix

The second matrix.

Returns: Matrix

Matrix which is the result of the multiplication.
static Matrix.xAxisRotation()

static

xAxisRotation(degrees: number): Matrix

Returns the matrix for a clockwise rotation around the X-axis.

Parameters

degrees: number

The degrees of the rotation.

Returns: Matrix

The rotation matrix.
static Matrix.yAxisRotation()

static

yAxisRotation(degrees: number): Matrix

Returns the matrix for a clockwise rotation around the Y-axis.

Parameters

degrees: number

The degrees of the rotation.

Returns: Matrix

The rotation matrix.
static Matrix.zAxisRotation()

static

zAxisRotation(degrees: number): Matrix

Returns the matrix for a clockwise rotation around the Z-axis.

Parameters

degrees: number

The degrees of the rotation.

Returns: Matrix

The rotation matrix.