Matrix
Represents a 3x3 transformation matrix in the following form:
a c e
( b d f )
0 0 1
a number
The a (1, 1)
member of the matrix.
b number
The b (2, 1)
member of the matrix.
c number
The c (1, 2)
member of the matrix.
d number
The d (2, 2)
member of the matrix.
e number
The e (1, 3) member of the matrix.
f number
The f (2, 3)
member of the matrix.
Constructors
Matrix (a?: number, b?: number, c?: number, d?: number, e?: number, f?: number)
Creates a transformation matrix with the specified parameters.
Parameters
a? number
The a (1, 1)
member of the matrix.
b? number
The b (2, 1)
member of the matrix.
c? number
The c (1, 2)
member of the matrix.
d? number
The d (2, 2)
member of the matrix.
e? number
The e (1, 3)
member of the matrix.
f? number
The f (2, 3)
member of the matrix.
Methods
clone
Creates a new instance with the same element values.
Returns
Matrix - A new Matrix instance with the same element values.
equals
Compares this matrix with another instance.
Parameters
other Matrix
The matrix instance to compare with.
Returns
boolean true if the matrix elements match. Otherwise, returns false
.
multiplyCopy
Multiplies the matrix by another one and returns the result as a new instance. The current instance elements are not altered.
Parameters
matrix Matrix
The matrix to multiply by.
Returns
Matrix - The result of the multiplication.
round
Rounds the matrix elements to the specified number of fractional digits.
Parameters
digits number
The number of fractional digits.
Returns
Matrix - The current matrix instance.
toArray
Returns the matrix elements as an [a, b, c, d, e, f]
array.
Parameters
digits? number
The number of fractional digits.
Returns
number[] - An array representation of the matrix.
toString
Formats the matrix elements as a string.
Parameters
digits? number
The number of fractional digits.
separator? string
The separator to place between elements.
Returns
string - A string representation of the matrix. For example, "1, 0, 0, 1, 0, 0"
.
rotate
Creates a transformation matrix for rotation with the specified parameters.
Parameters
angle number
The angle of rotation in decimal degrees. Measured in a clockwise direction with 0 (zero) pointing "right". Negative values or values greater than 360 are normalized.
x number
The center of rotation on the X axis.
y number
The center of rotation on the Y axis.
Returns
Matrix - The transformation matrix for the specified rotation.
scale
Creates a transformation matrix for the scale with the specified parameters.
Parameters
scaleX number
The scale factor on the X axis.
scaleY number
The scale factor on the Y axis.
Returns
Matrix - The transformation matrix for the specified scale.
translate
Creates a transformation matrix for the translation with the specified parameters.
Parameters
x number
The distance to translate along the X axis.
y number
The distance to translate along the Y axis.
Returns
Matrix - The transformation matrix for the specified translation.
unit
Returns the unit (identity) transformation matrix.
Returns
Matrix - The unit (identity) matrix.