Skip to content
Matrix4x4

[Basic Type](../groups/Basic Type.Basic Type.md) / Matrix4x4

Matrix4x4 Class

Four-dimensional matrix


Precautions

Column matrix

Table of contents

Properties

m00: number
The element in column 0 and row 0 of the matrix.
m01: number
The element in column 0 and row 1 of the matrix.
m02: number
The elements in column 0 and row 2 of the matrix.
m03: number
The element in column 0 and row 3 of the matrix.
m10: number
The element in column 1, row 0 of the matrix.
m11: number
The elements in the first column and first row of the matrix.
m12: number
The elements in column 1 and row 2 of the matrix.
m13: number
The elements in the first column and third row of the matrix.
m20: number
The element in column 2, row 0 of the matrix.
m21: number
The elements in the second column and first row of the matrix.
m22: number
The elements in the second column and second row of the matrix.
m23: number
The elements in the second column and third row of the matrix.
m30: number
The element in column 3, row 0 of the matrix.
m31: number
The elements in the third column and first row of the matrix.
m32: number
The elements in the second row of the third column of the matrix.
m33: number
The elements in the third column and third row of the matrix.

Accessors

identity(): void other
Set the current matrix as the identity matrix.

Methods

add(mat: Matrix4x4): Matrix4x4 other
Matrix addition. Add the current matrix to the specified matrix and return the result to the current matrix.
clone(a: Matrix4x4): Matrix4x4 other
Obtain a copy of the specified matrix
determinant(): number other
Calculate the determinant of the current matrix.
equals(other: Matrix4x4, epsilon?: number): boolean other
Determine whether the current matrix is equal to the specified matrix within the error range.
fromQuaternion(q: Quaternion): Matrix4x4 other
Reset the value of the current matrix to represent the rotation transformation represented by the specified quaternion.
fromRTS(q: Quaternion, v: Vector, s: Vector): Matrix4x4 other
Reset the value of the current matrix to represent the specified combination of rotation, scaling, and displacement transformation.
getRotation(outer?: Quaternion): Quaternion other
Calculate the part of the rotation transformation from the current matrix and assign it to the output quaternion in the form of a quaternion.
getScale(outer?: Vector): Vector other
Calculate the part of scale transformation from the current matrix, and assign the value to the exit vector in the form of scale on each axis.
getTranslation(outer?: Vector): Vector other
Calculate the displacement transformation part from the current matrix and assign it to the exit vector in the form of displacement on each axis.
identity(): void other
Set the current matrix as the identity matrix.
invert(a: Matrix4x4, outer?: Matrix4x4): Matrix4x4 other
Inverse the matrix, note that when the matrix is irreversible, it will return a matrix with all zeros.
multiply
:-----
rotate(axis: Vector, rad: number, epsilon?: number): Matrix4x4 other
Assign the result of left multiplication of the current matrix by the rotation matrix to the current matrix. The rotation matrix is given by the rotation axis and rotation angle.
scale(vec: Vector): Matrix4x4 other
Assign the result of the left multiplication scaling matrix of the current matrix to the current matrix, where the scaling matrix is given by the scaling of each axis.
set(other: Matrix4x4): Matrix4x4 other
Set the current matrix to be equal to the specified matrix.
strictEquals(other: Matrix4x4): boolean other
Determine whether the current matrix is equal to the specified matrix.
subtract(mat: Matrix4x4): Matrix4x4 other
Calculate matrix subtraction. Assign the result of subtracting the specified matrix from the current matrix to the current matrix.
toString(): string other
Returns the string representation of the current matrix.
translate(vec: Vector): Matrix4x4 other
Assign the result of the left multiplication of the current matrix by the displacement matrix to the current matrix, and the displacement matrix is given by the displacement of each axis.
transpose(a: Matrix4x4, outer?: Matrix4x4): Matrix4x4 other
Transpose matrix
zero
clone(a: Matrix4x4): Matrix4x4 other
Obtain a copy of the specified matrix
invert(a: Matrix4x4, outer?: Matrix4x4): Matrix4x4 other
Inverse the matrix, note that when the matrix is irreversible, it will return a matrix with all zeros.
transformAffine(m: Matrix4x4, a: Vector, outer?: Vector): Vector other
Vector affine transformation
transformAffine4(m: Matrix4x4, a: Vector4, outer?: Vector4): Vector4 other
Four-dimensional vector affine transformation
transformVector(m: Matrix4x4, a: Vector, outer?: Vector): Vector other
Multiplying a vector with a four-dimensional matrix, the fourth bit of the vector is assumed to be 0.
transformVector2(m: Matrix4x4, a: Vector2, outer?: Vector2): Vector2 other
When multiplying a vector and a four-dimensional matrix, the third bit of the vector is 0 by default, and the fourth bit is 1.
transformVector4(m: Matrix4x4, a: Vector4, outer?: Vector4): Vector4 other
Four-dimensional vector and four-dimensional matrix multiplication
transpose(a: Matrix4x4, outer?: Matrix4x4): Matrix4x4 other
Transpose matrix

Build a new Matrix4x4 using the given other

Parameters

other Matrix4x4Usage: Given Matrix4x4 object

new Matrix4x4(m00?, m01?, m02?, m03?, m10?, m11?, m12?, m13?, m20?, m21?, m22?, m23?, m30?, m31?, m32?, m33?)

Build a new Matrix4x4 using the given elements

Parameters

m00? numberUsage: element in column 0, line 0 default: 1 range: no restrictions type: floating point number
m01? numberUsage: Element in column 0, line 1 default: 0 range: No restrictions type: Floating point number
m02? numberUsage: element in column 0, line 2 default: 0 range: no restrictions type: floating point number
m03? numberUsage: element in column 0, line 3 default: 0 range: no restrictions type: floating point number
m10? numberUsage: element in column 1, line 0 default: 0 range: no restrictions type: floating point number
m11? numberUsage: element in column 1, line 1 default: 1 range: no restrictions type: floating point number
m12? numberUsage: Element in column 1, line 2 default: 0 range: No restrictions type: Floating point number
m13? numberUsage: element in column 1, line 3 default: 0 range: no restrictions type: floating point number
m20? numberUsage: element in column 2, line 0 default: 0 range: no restrictions type: floating point number
m21? numberUsage: Element in column 2, line 1 default: 0 range: No restrictions type: Floating point number
m22? numberUsage: element in column 2, line 2 default: 1 range: no restrictions type: floating point number
m23? numberUsage: Element in column 2, line 3 default: 0 range: No restrictions type: Floating point number
m30? numberUsage: element in column 3, line 0 default: 0 range: no restrictions type: floating point number
m31? numberUsage: Element in column 3, line 1 default: 0 range: No restrictions type: Floating point number
m32? numberUsage: Element in column 3, line 2 default: 0 range: No restrictions type: Floating point number
m33? numberUsage: element in column 3, line 3 default: 1 range: no restrictions type: floating point number

Properties

m00

m00: number

The element in column 0 and row 0 of the matrix.


m01

m01: number

The element in column 0 and row 1 of the matrix.


m02

m02: number

The elements in column 0 and row 2 of the matrix.


m03

m03: number

The element in column 0 and row 3 of the matrix.


m10

m10: number

The element in column 1, row 0 of the matrix.


m11

m11: number

The elements in the first column and first row of the matrix.


m12

m12: number

The elements in column 1 and row 2 of the matrix.


m13

m13: number

The elements in the first column and third row of the matrix.


m20

m20: number

The element in column 2, row 0 of the matrix.


m21

m21: number

The elements in the second column and first row of the matrix.


m22

m22: number

The elements in the second column and second row of the matrix.


m23

m23: number

The elements in the second column and third row of the matrix.


m30

m30: number

The element in column 3, row 0 of the matrix.


m31

m31: number

The elements in the third column and first row of the matrix.


m32

m32: number

The elements in the second row of the third column of the matrix.


m33

m33: number

The elements in the third column and third row of the matrix.

Accessors

identity

Static get identity(): Matrix4x4

Obtain a default matrix

Methods

add

add(mat): Matrix4x4 other

Matrix addition. Add the current matrix to the specified matrix and return the result to the current matrix.

Parameters

mat Matrix4x4Usage: additive matrix

Returns

Matrix4x4this

clone

clone(): Matrix4x4 other

Clone the current matrix.

Parameters

a Matrix4x4Usage: Cloned four-dimensional matrix

Returns

Matrix4x4Return the cloned new matrix

determinant

determinant(): number other

Calculate the determinant of the current matrix.

Returns

numberThe determinant of the current matrix.

equals

equals(other, epsilon?): boolean other

Determine whether the current matrix is equal to the specified matrix within the error range.

Parameters

other Matrix4x4Usage: Matrix for comparison
epsilon? numberUsage: Error value default: MathUtil.EPSILON
range: It is recommended to pass in a value less than 1. Type: Floating point number

Returns

booleanReturn the result of matrix comparison

fromQuaternion

fromQuaternion(q): Matrix4x4 other

Reset the value of the current matrix to represent the rotation transformation represented by the specified quaternion.

Parameters

q QuaternionUsage: Quaternions for rotating data

Returns

Matrix4x4this

fromRTS

fromRTS(q, v, s): Matrix4x4 other

Reset the value of the current matrix to represent the specified combination of rotation, scaling, and displacement transformation.

Parameters

q QuaternionUsage: Quaternions for rotating data
v VectorUsage: Vector of displacement data
s VectorUsage: scale data vector

Returns

Matrix4x4this

getRotation

getRotation(outer?): Quaternion other

Calculate the part of the rotation transformation from the current matrix and assign it to the output quaternion in the form of a quaternion.

Parameters

outer? QuaternionUsage: Quaternion object that receives rotated data, default: null

Returns

QuaternionQuaternion object for recording rotation data

Precautions

If the outer is not empty, return the outer, otherwise return a new Quaternion object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined


getScale

getScale(outer?): Vector other

Calculate the part of scale transformation from the current matrix, and assign the value to the exit vector in the form of scale on each axis.

Parameters

outer? VectorUsage: Vector object receiving scale data default: null

Returns

VectorScale Data

Precautions

If the outer is not empty, return the outer. Otherwise, return a new Vector object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined


getTranslation

getTranslation(outer?): Vector other

Calculate the displacement transformation part from the current matrix and assign it to the exit vector in the form of displacement on each axis.

Parameters

outer? VectorUsage: Vector object for receiving displacement data default: null

Returns

VectorDisplacement data

Precautions

If the outer is not empty, return the outer. Otherwise, return a new Vector object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined


identity

identity(): void other

Set the current matrix as the identity matrix.


invert

invert(): void other

Transform the current matrix into an inverse matrix. Note that when the matrix is irreversible, a matrix with all zeros will be returned.

Parameters

a Matrix4x4Usage: Original matrix
outer? Matrix4x4Usage: Matrix4x4 object receiving results default: null

Returns

Matrix4x4Inverse matrix

Matrix multiplication. Assign the result of left multiplication of the specified matrix to the current matrix.

Parameters

mat Matrix4x4Usage: Multiplying matrices

Returns

Matrix4x4this

multiply(scalar): Matrix4x4 other

Matrix multiplication. Assign the multiplication result of the current matrix and the specified scalar to the current matrix.

Parameters

scalar numberUsage: The number to scale the matrix as a whole. range: No restrictions. type: Floating point number

Returns

Matrix4x4this

rotate

rotate(axis, rad, epsilon?): Matrix4x4 other

Assign the result of left multiplication of the current matrix by the rotation matrix to the current matrix. The rotation matrix is given by the rotation axis and rotation angle.

Parameters

axis VectorUsage: rotation axis around
rad numberUsage: Rotation radians
range: Unlimited type: Floating point number
epsilon? numberUsage: Minimum error count default: MathDefine EPSILON
range: It is recommended to pass in a value less than 1. Type: Floating point number

Returns

Matrix4x4this

scale

scale(vec): Matrix4x4 other

Assign the result of the left multiplication scaling matrix of the current matrix to the current matrix, where the scaling matrix is given by the scaling of each axis.

Parameters

vec VectorUsage: Vector of scaling matrix

Returns

Matrix4x4this

set

set(other): Matrix4x4 other

Set the current matrix to be equal to the specified matrix.

Parameters

other Matrix4x4Usage: Matrix data

Returns

Matrix4x4this

set(m00?, m01?, m02?, m03?, m10?, m11?, m12?, m13?, m20?, m21?, m22?, m23?, m30?, m31?, m32?, m33?): Matrix4x4 other

Set the current matrix to specify element values.

Parameters

m00? numberUsage: element in column 0, line 0 default: 1 range: no restrictions type: floating point number
m01? numberUsage: Element in column 0, line 1 default: 0 range: No restrictions type: Floating point number
m02? numberUsage: element in column 0, line 2 default: 0 range: no restrictions type: floating point number
m03? numberUsage: element in column 0, line 3 default: 0 range: no restrictions type: floating point number
m10? numberUsage: element in column 1, line 0 default: 0 range: no restrictions type: floating point number
m11? numberUsage: element in column 1, line 1 default: 1 range: no restrictions type: floating point number
m12? numberUsage: Element in column 1, line 2 default: 0 range: No restrictions type: Floating point number
m13? numberUsage: element in column 1, line 3 default: 0 range: no restrictions type: floating point number
m20? numberUsage: element in column 2, line 0 default: 0 range: no restrictions type: floating point number
m21? numberUsage: Element in column 2, line 1 default: 0 range: No restrictions type: Floating point number
m22? numberUsage: element in column 2, line 2 default: 1 range: no restrictions type: floating point number
m23? numberUsage: Element in column 2, line 3 default: 0 range: No restrictions type: Floating point number
m30? numberUsage: element in column 3, line 0 default: 0 range: no restrictions type: floating point number
m31? numberUsage: Element in column 3, line 1 default: 0 range: No restrictions type: Floating point number
m32? numberUsage: Element in column 3, line 2 default: 0 range: No restrictions type: Floating point number
m33? numberUsage: element in column 3, line 3 default: 1 range: no restrictions type: floating point number

Returns

Matrix4x4this

strictEquals

strictEquals(other): boolean other

Determine whether the current matrix is equal to the specified matrix.

Parameters

other Matrix4x4Usage: Matrix for comparison

Returns

booleanReturn the result of matrix comparison

subtract

subtract(mat): Matrix4x4 other

Calculate matrix subtraction. Assign the result of subtracting the specified matrix from the current matrix to the current matrix.

Parameters

mat Matrix4x4Usage: Subtraction matrix

Returns

Matrix4x4this

toString

toString(): string other

Returns the string representation of the current matrix.

Returns

stringThe string representation of the current matrix.

translate

translate(vec): Matrix4x4 other

Assign the result of the left multiplication of the current matrix by the displacement matrix to the current matrix, and the displacement matrix is given by the displacement of each axis.

Parameters

vec VectorUsage: transformed vector

Returns

Matrix4x4this

transpose

transpose(): void other

Transform the current matrix into a transposed matrix.

Parameters

a Matrix4x4Usage: transposed original matrix
outer? Matrix4x4Usage: Matrix4x4 object receiving results default: null

Returns

Matrix4x4Transpose matrix

Set the current matrix to a 0 matrix.


clone

Static clone(a): Matrix4x4 other

Obtain a copy of the specified matrix

Parameters

a Matrix4x4Usage: Cloned four-dimensional matrix

Returns

Matrix4x4Return the cloned new matrix

invert

Static invert(a, outer?): Matrix4x4 other

Inverse the matrix, note that when the matrix is irreversible, it will return a matrix with all zeros.

Precautions

If the outer is not empty, return the outer. Otherwise, return a new Matrix4x4 object. It is recommended to pass in the outer to reduce the number of new objects, and the outer cannot be null/undefined

Parameters

a Matrix4x4Usage: Original matrix
outer? Matrix4x4Usage: Matrix4x4 object receiving results default: null

Returns

Matrix4x4Inverse matrix

transformAffine

Static transformAffine(m, a, outer?): Vector other

Vector affine transformation

Parameters

m Matrix4x4Usage: Four dimensional matrix
a VectorUsage: 3D vectors
outer? VectorUsage: Vector object for receiving results default: null

Returns

VectorThe vector obtained after affine transformation

Precautions

If the outer is not empty, return the outer. Otherwise, return a new Vector object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined


transformAffine4

Static transformAffine4(m, a, outer?): Vector4 other

Four-dimensional vector affine transformation

Parameters

m Matrix4x4Usage: Four dimensional matrix
a Vector4Usage: Four dimensional vector
outer? Vector4Usage: Vector4 object receiving results default: null

Returns

Vector4The four-dimensional vector obtained after affine transformation

Precautions

If the outer is not empty, return the outer. Otherwise, return a new Vector4 object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined


transformVector

Static transformVector(m, a, outer?): Vector other

Multiplying a vector with a four-dimensional matrix, the fourth bit of the vector is assumed to be 0.

Parameters

m Matrix4x4Usage: four-dimensional matrix being multiplied
a VectorUsage: Multiplying a three-dimensional vector by a matrix
outer? VectorUsage: Vector object for receiving results default: null

Returns

VectorThe vector obtained after conversion

Precautions

If the outer is not empty, return the outer. Otherwise, return a new Vector object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined


transformVector2

Static transformVector2(m, a, outer?): Vector2 other

When multiplying a vector and a four-dimensional matrix, the third bit of the vector is 0 by default, and the fourth bit is 1.

Parameters

m Matrix4x4Usage: four-dimensional matrix being multiplied
a Vector2Usage: Multiplying a two-dimensional vector by a matrix
outer? Vector2Usage: Vector2 object for receiving results default: null

Returns

Vector2Return the transformed new two-dimensional vector

Precautions

If the outer is not empty, return the outer. Otherwise, return a new Vector2 object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined


transformVector4

Static transformVector4(m, a, outer?): Vector4 other

Four-dimensional vector and four-dimensional matrix multiplication

Parameters

m Matrix4x4Usage: four-dimensional matrix being multiplied
a Vector4Usage: Multiplying the four-dimensional vector of a matrix
outer? Vector4Usage: Vector4 object receiving results default: null

Returns

Vector4The four-dimensional vector obtained after conversion

Precautions

If the outer is not empty, return the outer. Otherwise, return a new Vector4 object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined


transpose

Static transpose(a, outer?): Matrix4x4 other

Transpose matrix

Precautions

If the outer is not empty, return the outer. Otherwise, return a new Matrix4x4 object. It is recommended to pass in the outer to reduce the number of new objects, and the outer cannot be null/undefined

Parameters

a Matrix4x4Usage: transposed original matrix
outer? Matrix4x4Usage: Matrix4x4 object receiving results default: null

Returns

Matrix4x4Transpose matrix