web api interface
DOMMatrix
Available in workers
The DOMMatrix interface represents 4×4 matrices, suitable for 2D and 3D operations including rotation and translation. It is a mutable version of the DOMMatrixReadOnly interface.
The interface is available inside web workers.
WebKitCSSMatrix and SVGMatrix are aliases to DOMMatrix.
Constructor
DOMMatrix()- : Creates and returns a new
DOMMatrixobject.
- : Creates and returns a new
Instance properties
This interface inherits properties from DOMMatrixReadOnly, though some of these properties are altered to be mutable.
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 4×4 matrix, where
m11throughm14are the first column,m21throughm24are the second column, and so forth.
- : Double-precision floating-point values representing each component of a 4×4 matrix, where
a,b,c,d,e,f-
: Double-precision floating-point values representing the components of a 4×4 matrix which are required in order to perform 2D rotations and translations. These are aliases for specific components of a 4×4 matrix, as shown below.
2D3D equivalentam11bm12cm21dm22em41fm42
-
Instance methods
This interface includes the following methods, as well as the methods it inherits from DOMMatrixReadOnly.
invertSelf()- : Modifies the matrix by inverting it. If the matrix can’t be inverted, its components are all set to
NaN, andis2Dreturnsfalse.
- : Modifies the matrix by inverting it. If the matrix can’t be inverted, its components are all set to
multiplySelf()- : Modifies the matrix by post-multiplying it with the specified
DOMMatrix. This is equivalent to the dot productA⋅B, where matrixAis the source matrix andBis the matrix given as an input to the method. Returns itself.
- : Modifies the matrix by post-multiplying it with the specified
preMultiplySelf()- : Modifies the matrix by pre-multiplying it with the specified
DOMMatrix. Returns itself.
- : Modifies the matrix by pre-multiplying it with the specified
translateSelf()- : Modifies the matrix by applying the specified vector. The default vector is
[0, 0, 0]. Returns itself.
- : Modifies the matrix by applying the specified vector. The default vector is
scaleSelf()- : Modifies the matrix by applying the specified scaling factors, with the center located at the specified origin. Also returns itself. By default, the scaling factor is
1for all three axes, and the origin is(0, 0, 0). Returns itself.
- : Modifies the matrix by applying the specified scaling factors, with the center located at the specified origin. Also returns itself. By default, the scaling factor is
scale3dSelf()- : Modifies the matrix by applying the specified scaling factor to all three axes, centered on the given origin. Returns itself.
rotateSelf()- : Modifies the matrix by rotating itself around each axis by the specified number of degrees. Returns itself.
rotateAxisAngleSelf()- : Modifies the matrix by rotating it by the specified angle around the given vector. Returns itself.
rotateFromVectorSelf()- : Modifies the matrix by rotating it by the angle between the specified vector and
(1, 0). Returns itself.
- : Modifies the matrix by rotating it by the angle between the specified vector and
setMatrixValue()- : Replaces the contents of the matrix with the matrix described by the specified transform or transforms. Returns itself.
skewXSelf()- : Modifies the matrix by applying the specified skew transformation along the X-axis. Returns itself.
skewYSelf()- : Modifies the matrix by applying the specified skew transformation along the Y-axis. Returns itself.
Static methods
fromFloat32Array()- : Creates a new
DOMMatrixobject given aFloat32Arrayof 6 or 16 single-precision (32-bit) floating-point values.
- : Creates a new
fromFloat64Array()- : Creates a new
DOMMatrixobject given aFloat64Arrayof 6 or 16 double-precision (64-bit) floating-point values.
- : Creates a new
fromMatrix()- : Creates a new
DOMMatrixobject given an existing matrix or an object which provides the values for its properties.
- : Creates a new
Usage notes
The matrix defined by the DOMMatrix interface is comprised of four rows of four columns each. While it’s beyond the scope of this article to explain the mathematics involved, this 4×4 size is enough to describe any transformation you might apply to either 2D or 3D geometries.
Here are the positions of the 16 elements (m_11 through m_44) which comprise the 4×4 abstract matrix:
The DOMMatrix interface is designed with the intent that it will be used for all matrices within markup.