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.
2D | 3D |
---|---|
a | m11 |
b | m12 |
c | m21 |
d | m22 |
tx | m41 |
ty | m42 |
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:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value | Float32Array | <optional> | IDENTITY | Matrix data |
multiplicationType | Common.Matrix.MultiplicationType | <optional> | MultiplicationType.PRE | Multiplication type |
Properties:
Name | Type | Description |
---|---|---|
isIdentity | boolean | A 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). |
translateX | float | X axis translation |
translateY | float | Y axis translation |
skewX | float | X axis skew angle in rad |
skewY | float | Y axis skew angle in rad |
scaleX | float | X axis scale factor |
scaleY | float | Y axis scale factor |
rotation | float | Z 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
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:
Name | Type | Description |
---|---|---|
delta | Common.Matrix |
Returns:
Transform as new Matrix
Type
multiplySelf(delta)
Modifies the matrix by post or pre multiplying (specified by multiplication type) it with the specified Matrix
Parameters:
Name | Type | Description |
---|---|---|
delta | Common.Matrix |
postMultiply(delta) → Common.Matrix
Post multiplication (moving coordinate system (Euler frame), fixed point)The original matrix is not altered.
Parameters:
Name | Type | Description |
---|---|---|
delta | Common.Matrix |
Returns:
Transform as new Matrix
Type
postMultiplySelf(delta)
Post multiplication (moving coordinate system (Euler frame), fixed point)
Parameters:
Name | Type | Description |
---|---|---|
delta | Common.Matrix |
preMultiply(delta) → Common.Matrix
Pre multiplication (fixed coordinate system (fixed frame), moving point)The original matrix is not altered.
Parameters:
Name | Type | Description |
---|---|---|
delta | Common.Matrix |
Returns:
Transform as new Matrix
Type
preMultiplySelf(delta)
Pre multiplication (fixed coordinate system (fixed frame), moving point)
Parameters:
Name | Type | Description |
---|---|---|
delta | Common.Matrix |
rotate(alpha, originopt) → Common.Matrix
Applys 2D rotation. The original matrix is not altered.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
alpha | float | Value should be in rad | ||
origin | Common.Point | <optional> | {x: 0, y: 0} | Transform origin |
Returns:
Transform as new Matrix
Type
rotateSelf(alpha, originopt)
Applys 2D rotation
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
alpha | float | Value should be in rad | ||
origin | Common.Point | <optional> | {x: 0, y: 0} | Transform origin |
scale(factor, originopt) → Common.Matrix
Applys 2D scale. The original matrix is not altered.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
factor | Scale|float | Scale factor | ||
origin | Common.Point | <optional> | {x: 0, y: 0} | Transform origin |
Returns:
Transform as new Matrix
Type
scaleSelf(factor, originopt)
Applys 2D scale
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
factor | Scale|float | Scale factor | ||
origin | Common.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:
Name | Type | Description |
---|---|---|
whole | boolean | Generate matrix string as 4x4 |
Returns:
CSS transform value when whole is false
Type
string
transformPoint(point) → Common.Point
Transform point
Parameters:
Name | Type | Description |
---|---|---|
point | Common.Point | Point to transform |
Returns:
Transformed point
Type
translate(offset) → Common.Matrix
Applys 2D translation. The original matrix is not altered.
Parameters:
Name | Type | Description |
---|---|---|
offset | Translate |
Returns:
Transform as new Matrix
Type
translateSelf(offset)
Applys 2D translation
Parameters:
Name | Type | Description |
---|---|---|
offset | Translate |
(static) fromMatrix(data, multiplicationType) → Common.Matrix
Factory method for Matrix creation
Parameters:
Name | Type | Description |
---|---|---|
data | Array|Float32Array|Matrix2D|Matrix3D | |
multiplicationType | Common.MultiplicationType |
Returns:
Matrix based on data
Type
(static) fromPoints(ps, pf) → Common.Matrix
Creates transformation based on three points
Parameters:
Name | Type | Description |
---|---|---|
ps | Array.<Common.Point> | Fixed array with length 3. Starting points which should be transformed. |
pf | Array.<Common.Point> | Fixed array with length 3. Final points after transformation |
Returns:
Matrix which transforms starting points to final points
Type
(static) fromRotate(alpha, originopt) → Common.Matrix
Creates delta rotate matrix
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
alpha | float | Value should be in rad | ||
origin | Common.Point | <optional> | {x: 0, y: 0} | Transform origin |
Returns:
Transform as new Matrix
Type
(static) fromScale(factor, originopt) → Common.Matrix
Creates delta scale matrix
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
factor | Scale|float | Scale factor | ||
origin | Common.Point | <optional> | {x: 0, y: 0} | Transform origin |
Returns:
Transform as new Matrix
Type
(static) fromString(value, multiplicationType) → Common.Matrix
Parameters:
Name | Type | Description |
---|---|---|
value | string | CSS transform value |
multiplicationType | Common.MultiplicationType |
Returns:
Matrix based on this string
Type
(static) fromTranslate(offset) → Common.Matrix
Creates delta translate matrix
Parameters:
Name | Type | Description |
---|---|---|
offset | Translate |
Returns:
Transform as new Matrix
Type
(static) multiply(a, b) → {Matrix}
Multiplies matrices AxB
Parameters:
Name | Type | Description |
---|---|---|
a | Matrix | Matrix A |
b | Matrix | Matrix B |
Returns:
Transform as new Matrix
Type
Matrix
Type Definitions
MultiplicationType
Describes multiply operation matrices order. Affects multiply and multiplySelf methods.
Properties:
Name | Type | Description |
---|---|---|
PRE | object | Fixed coordinate system (fixed frame), moving point |
POST | object | Moving coordinate system (Euler frame), fixed point |