Class: Matrix

Matrix

2D Transformation Matrix.

new Matrix()

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 2927
2D transformation matrix object initialized with identity matrix.
Properties:
Name Type Description
a number scale x
b number shear y
c number shear x
d number scale y
e number translate x
f number translate y
Version:
  • 2.7.5
Author:
  • Epistemex
License:
  • MIT license (header required)

Methods

staticMatrix.from(a, b, c, d, e, f, context){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 2975
Create and transform a new matrix based on given matrix values, or provide SVGMatrix or a (2D) DOMMatrix, WebKitCSSMatrix or another instance of a generic matrix.
Name Type Description
a * number representing a (scale x) in [a-f], or a Matrix object containing properties a-f.
b * optional b property (shear y) if a is not a matrix object, or optional canvas 2D context. If vector is input this will be pre-translate for x.
c number optional c property (shear x)
d number optional d property (scale y)
e number optional e property (translate x)
f number optional f property (translate y)
context CanvasRenderingContext2D optional optional canvas context to synchronize
Returns:
Type Description
Matrix - new Matrix instance
Example
var m = Matrix.from(1, 0.2, 0, 2, 120, 97);
var m = Matrix.from(domMatrix, ctx);
var m = Matrix.from(svgMatrix);
var m = Matrix.from(matrix);

applyToPoint(pt){Array.<number>}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3229
Apply current matrix to `x` and `y` of a point. Returns a point object.
Name Type Description
pt Array.<number> the point to transform ([x, y]).
If an optionnal Z value is provided, it will be kept without transformation.
Returns:
Type Description
Array.<number> A new transformed point [x, y]. If pt had a third value, it is returned too, as it was without transformation.

clone(noContext){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3292
Clones current instance and returning a new matrix.
Name Type Default Description
noContext boolean false optional don't clone context reference if true
Returns:
Type Description
Matrix - a new Matrix instance with identical transformations as this instance

decompose(){*}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3167
Decompose the current matrix into simple transforms using QR.
See:
Returns:
Type Description
* - an object containing current decomposed values (translate, rotation, scale, skew)

determinant(){number}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3217
Returns the determinant of the current matrix.
Returns:
Type Description
number

inverse(cloneContext){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3142
Get an inverse matrix of current matrix. The method returns a new matrix with values you need to use to get to an identity matrix. Context from parent matrix is not applied to the returned matrix.
Name Type Default Description
cloneContext boolean false optional clone current context to resulting matrix
Throws:
Exception is input matrix is not invertible
Returns:
Type Description
Matrix - new Matrix instance

isEqual(m){boolean}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3273
Compares current matrix with another matrix. Returns true if equal (within epsilon tolerance).
Name Type Description
m Matrix | Matrix | DOMMatrix | SVGMatrix matrix to compare this matrix with
Returns:
Type Description
boolean

isIdentity(){boolean}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3242
Returns true if matrix is an identity matrix (no transforms applied).
Returns:
Type Description
boolean

isInvertible(){boolean}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3251
Returns true if matrix is invertible
Returns:
Type Description
boolean

isValid(){boolean}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3263
The method is intended for situations where scale is accumulated via multiplications, to detect situations where scale becomes "trapped" with a value of zero. And in which case scale must be set explicitly to a non-zero value.
Returns:
Type Description
boolean

multiply(m){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3129
Multiplies current matrix with source matrix.
Name Type Description
m Matrix | Matrix | DOMMatrix | SVGMatrix source matrix to multiply with.
Returns:
Type Description
Matrix

reset(){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 2997
Short-hand to reset current matrix to an identity matrix.
Returns:
Type Description
Matrix

rotate(angle){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3006
Rotates current matrix by angle (accumulative).
Name Type Description
angle number angle in degrees
Returns:
Type Description
Matrix

rotateFromVector(x, y){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3023
Converts a vector given as `x` and `y` to angle, and rotates (accumulative). x can instead contain an object with properties x and y and if so, y parameter will be ignored.
Name Type Description
x number | *
y number optional
Returns:
Type Description
Matrix

scale(s){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3032
Scales current matrix accumulative.
Name Type Description
s Array.<number> scale factor [x, y]. 1 does nothing, any third value (Z) is ignored.
Returns:
Type Description
Matrix

setTransform(a, b, c, d, e, f){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3067
Set current matrix to new absolute matrix.
Name Type Description
a number scale x
b number shear y
c number shear x
d number scale y
e number translate x
f number translate y
Returns:
Type Description
Matrix

shear(sx, sy){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3042
Apply shear to the current matrix accumulative.
Name Type Description
sx number amount of shear for x
sy number amount of shear for y
Returns:
Type Description
Matrix

skew(ax, ay){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3053
Apply skew to the current matrix accumulative. Angles in radians. Also see `skewDeg()`.
Name Type Description
ax number angle of skew for x
ay number angle of skew for y
Returns:
Type Description
Matrix

toCSS(){string}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3302
Generates a string that can be used with CSS `transform`.
Returns:
Type Description
string
Example
element.style.transform = m.toCSS();

toCSS3D(){string}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3314
Generates a `matrix3d()` string that can be used with CSS `transform`. Although the matrix is for 2D use you may see performance benefits on some devices using a 3D CSS transform instead of a 2D.
Returns:
Type Description
string
Example
element.style.transform = m.toCSS3D();

toJSON(){string}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3323
Returns a JSON compatible string of current matrix.
Returns:
Type Description
string

transform(a2, b2, c2, d2, e2, f2){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3098
Multiplies current matrix with new matrix values. Also see `multiply()`.
Name Type Description
a2 number scale x
b2 number skew y
c2 number skew x
d2 number scale y
e2 number translate x
f2 number translate y
Returns:
Type Description
Matrix

translate(t){Matrix}

D:/RxLab/src/RxOT/DuAEF/Duik/Duik_API/DuAEF_Duik_api.jsxinc, line 3083
Translate current matrix accumulative.
Name Type Description
t Array.<number> translation [x, y]. Any third value (Z) is ignored.
Returns:
Type Description
Matrix