Skip to main content

Class: Matrix

Common.Matrix(valueopt, multiplicationTypeopt)

Represents 4x4 matrix, sutiable for 2D operations, based on gl-matrix - mat4

a, b, c, d, tx, ty -Double-precision floating-point values representing the components of a 4x4 matrix which are required in order to perform 2D rotations and translations.These are aliases for specific components of a 4x4 matrix, as shown below.

2D3D
am11
bm12
cm21
dm22
txm41
tym42

m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44 -Double-precision floating-point values representing each component of a 4x4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth <xmp>| m11 m21 m31 m41 | | m12 m22 m32 m42 | | m13 m23 m33 m43 | | m14 m24 m34 m44 |</xmp>

Constructor

new Matrix(valueopt, multiplicationTypeopt)

Creates a matrix

Parameters:
NameTypeAttributesDefaultDescription
valueFloat32Array<optional>IDENTITYMatrix data
multiplicationTypeCommon.Matrix.MultiplicationType<optional>MultiplicationType.PREMultiplication type
Properties:
NameTypeDescription
isIdentitybooleanA Boolean whose value is true if the matrix is the identity matrix.The identity matrix is one in which every value is 0 except those on the main diagonal from top-left to bottom-right corner (in other words, where the offsets in each direction are equal).
translateXfloatX axis translation
translateYfloatY axis translation
skewXfloatX axis skew angle in rad
skewYfloatY axis skew angle in rad
scaleXfloatX axis scale factor
scaleYfloatY axis scale factor
rotationfloatZ axis rotation angle in rad

See:

Methods

decompose() → {MatrixData}

Decompose matrix to translate, rotate, skew and scale

Returns:

Decomposed matrix

Type

MatrixData

invert() → Common.Matrix

Inverts matrix. The original matrix is not altered.

Returns:

Transform as new Matrix

Type

Common.Matrix

invertSelf()

Inverts matrix

multiply(delta) → Common.Matrix

Multiplies with matrix by post or pre multiplying (specified by multiplication type).The original matrix is not altered.

Parameters:
NameTypeDescription
deltaCommon.Matrix
Returns:

Transform as new Matrix

Type

Common.Matrix

multiplySelf(delta)

Modifies the matrix by post or pre multiplying (specified by multiplication type) it with the specified Matrix

Parameters:
NameTypeDescription
deltaCommon.Matrix

postMultiply(delta) → Common.Matrix

Post multiplication (moving coordinate system (Euler frame), fixed point)The original matrix is not altered.

Parameters:
NameTypeDescription
deltaCommon.Matrix
Returns:

Transform as new Matrix

Type

Common.Matrix

postMultiplySelf(delta)

Post multiplication (moving coordinate system (Euler frame), fixed point)

Parameters:
NameTypeDescription
deltaCommon.Matrix

preMultiply(delta) → Common.Matrix

Pre multiplication (fixed coordinate system (fixed frame), moving point)The original matrix is not altered.

Parameters:
NameTypeDescription
deltaCommon.Matrix
Returns:

Transform as new Matrix

Type

Common.Matrix

preMultiplySelf(delta)

Pre multiplication (fixed coordinate system (fixed frame), moving point)

Parameters:
NameTypeDescription
deltaCommon.Matrix

rotate(alpha, originopt) → Common.Matrix

Applys 2D rotation. The original matrix is not altered.

Parameters:
NameTypeAttributesDefaultDescription
alphafloatValue should be in rad
originCommon.Point<optional>{x: 0, y: 0}Transform origin
Returns:

Transform as new Matrix

Type

Common.Matrix

rotateSelf(alpha, originopt)

Applys 2D rotation

Parameters:
NameTypeAttributesDefaultDescription
alphafloatValue should be in rad
originCommon.Point<optional>{x: 0, y: 0}Transform origin

scale(factor, originopt) → Common.Matrix

Applys 2D scale. The original matrix is not altered.

Parameters:
NameTypeAttributesDefaultDescription
factorScale|floatScale factor
originCommon.Point<optional>{x: 0, y: 0}Transform origin
Returns:

Transform as new Matrix

Type

Common.Matrix

scaleSelf(factor, originopt)

Applys 2D scale

Parameters:
NameTypeAttributesDefaultDescription
factorScale|floatScale factor
originCommon.Point<optional>{x: 0, y: 0}Transform origin

toFloat32Array() → {Float32Array}

Returns:

Matrix data as array

Type

Float32Array

toJSON() → {JSON}

Returns:

Matrix data

Type

JSON

toString(whole) → {string}

Stringify matrix

Parameters:
NameTypeDescription
wholebooleanGenerate matrix string as 4x4
Returns:

CSS transform value when whole is false

Type

string

transformPoint(point) → Common.Point

Transform point

Parameters:
NameTypeDescription
pointCommon.PointPoint to transform
Returns:

Transformed point

Type

Common.Point

translate(offset) → Common.Matrix

Applys 2D translation. The original matrix is not altered.

Parameters:
NameTypeDescription
offsetTranslate
Returns:

Transform as new Matrix

Type

Common.Matrix

translateSelf(offset)

Applys 2D translation

Parameters:
NameTypeDescription
offsetTranslate

(static) fromMatrix(data, multiplicationType) → Common.Matrix

Factory method for Matrix creation

Parameters:
NameTypeDescription
dataArray|Float32Array|Matrix2D|Matrix3D
multiplicationTypeCommon.MultiplicationType
Returns:

Matrix based on data

Type

Common.Matrix

(static) fromPoints(ps, pf) → Common.Matrix

Creates transformation based on three points

Parameters:
NameTypeDescription
psArray.<Common.Point>Fixed array with length 3. Starting points which should be transformed.
pfArray.<Common.Point>Fixed array with length 3. Final points after transformation
Returns:

Matrix which transforms starting points to final points

Type

Common.Matrix

(static) fromRotate(alpha, originopt) → Common.Matrix

Creates delta rotate matrix

Parameters:
NameTypeAttributesDefaultDescription
alphafloatValue should be in rad
originCommon.Point<optional>{x: 0, y: 0}Transform origin
Returns:

Transform as new Matrix

Type

Common.Matrix

(static) fromScale(factor, originopt) → Common.Matrix

Creates delta scale matrix

Parameters:
NameTypeAttributesDefaultDescription
factorScale|floatScale factor
originCommon.Point<optional>{x: 0, y: 0}Transform origin
Returns:

Transform as new Matrix

Type

Common.Matrix

(static) fromString(value, multiplicationType) → Common.Matrix

Parameters:
NameTypeDescription
valuestringCSS transform value
multiplicationTypeCommon.MultiplicationType
Returns:

Matrix based on this string

Type

Common.Matrix

(static) fromTranslate(offset) → Common.Matrix

Creates delta translate matrix

Parameters:
NameTypeDescription
offsetTranslate
Returns:

Transform as new Matrix

Type

Common.Matrix

(static) multiply(a, b) → {Matrix}

Multiplies matrices AxB

Parameters:
NameTypeDescription
aMatrixMatrix A
bMatrixMatrix B
Returns:

Transform as new Matrix

Type

Matrix

Type Definitions

MultiplicationType

Describes multiply operation matrices order. Affects multiply and multiplySelf methods.

Properties:
NameTypeDescription
PREobjectFixed coordinate system (fixed frame), moving point
POSTobjectMoving coordinate system (Euler frame), fixed point

Home