Two.Matrix

A class to store 3 x 3 transformation matrix information. In addition to storing data Two.Matrix has souped-up methods for commonplace mathematical operations.

Constructor

ArgumentDescription
aThe value for element at the first column and first row.
bThe value for element at the second column and first row.
cThe value for element at the third column and first row.
dThe value for element at the first column and second row.
eThe value for element at the second column and second row.
fThe value for element at the third column and second row.
gThe value for element at the first column and third row.
hThe value for element at the second column and third row.
iThe value for element at the third column and third row.

Identity

A stored reference to the default value of a 3 x 3 matrix.

Multiply

Returns: Array.<Number>

  • If an optional C matrix isn't passed then a new one is created and returned.
ArgumentDescription
AThe first Two.Matrix to multiply
BThe second Two.Matrix to multiply
CAn optional Two.Matrix to apply the result to

Multiply two matrices together and return the result.

fromObject

Returns: Two.Matrix

ArgumentDescription
objThe object notation of a Two.Matrix to create a new instance

Create a new Two.Matrix from an object notation of a Two.Matrix.

nota-bene

Works in conjunction with Two.Matrix.toObject

elements

The underlying data stored as an array.

manual

Determines whether Two.js automatically calculates the values for the matrix or if the developer intends to manage the matrix.

nota-bene

set

ArgumentDescription
aThe value for element at the first column and first row
bThe value for element at the second column and first row
cThe value for element at the third column and first row
dThe value for element at the first column and second row
eThe value for element at the second column and second row
fThe value for element at the third column and second row
gThe value for element at the first column and third row
hThe value for element at the second column and third row
iThe value for element at the third column and third row

Set an array of values onto the matrix. Order described in Two.Matrix.

set

ArgumentDescription
aThe array of elements to apply

Set an array of values onto the matrix. Order described in Two.Matrix.

copy

ArgumentDescription
mThe matrix to copy

Copy the matrix of one to the current instance.

identity

Turn matrix to the identity, like resetting.

multiply

Overloaded

ArgumentDescription
sThe scalar to be multiplied.

Multiply all components of the matrix against a single scalar value.

multiply

Overloaded

ArgumentDescription
xThe x component to be multiplied.
yThe y component to be multiplied.
zThe z component to be multiplied.

Multiply all components of a matrix against a 3 component vector.

multiply

Overloaded

ArgumentDescription
aThe value at the first column and first row of the matrix to be multiplied.
bThe value at the second column and first row of the matrix to be multiplied.
cThe value at the third column and first row of the matrix to be multiplied.
dThe value at the first column and second row of the matrix to be multiplied.
eThe value at the second column and second row of the matrix to be multiplied.
fThe value at the third column and second row of the matrix to be multiplied.
gThe value at the first column and third row of the matrix to be multiplied.
hThe value at the second column and third row of the matrix to be multiplied.
iThe value at the third column and third row of the matrix to be multiplied.

Multiply all components of a matrix against another matrix.

inverse

ArgumentDescription
outputThe optional matrix to apply the inversion to.

Return an inverted version of the matrix. If no optional one is passed a new matrix is created and returned.

scale

ArgumentDescription
sThe one dimensional scale to apply to the matrix.

Uniformly scale the transformation matrix.

scale

ArgumentDescription
sxThe horizontal scale factor.
syThe vertical scale factor

Scale the transformation matrix in two dimensions.

rotate

ArgumentDescription
nThe amount to rotate in Number.

Rotate the matrix.

translate

ArgumentDescription
xThe horizontal translation value to apply
yThe vertical translation value to apply

Translate the matrix to specific x / y values.

skewX

ArgumentDescription
nThe amount to skew

Skew the matrix by an angle in the x axis direction.

skewY

ArgumentDescription
nThe amount to skew

Skew the matrix by an angle in the y axis direction.

toString

Returns: String

  • The transformation matrix as a 6 component string separated by spaces.
ArgumentDescription
fullMatrixReturn the full 9 elements of the matrix or just 6 for 2D transformations.

Create a transform string. Used for the Two.js rendering APIs.

toTransformArray

ArgumentDescription
fullMatrixReturn the full 9 elements of the matrix or just 6 in the format for 2D transformations.
outputAn array empty or otherwise to apply the values to.

Create a transform array. Used for the Two.js rendering APIs.

toArray

ArgumentDescription
fullMatrixReturn the full 9 elements of the matrix or just 6 for 2D transformations.
outputAn array empty or otherwise to apply the values to.

Create a transform array. Used for the Two.js rendering APIs.

toObject

Create a JSON compatible object that represents information of the matrix.

nota-bene

Works in conjunction with Two.Matrix.fromObject

clone

Clone the current matrix.