Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. DOMMatrix

DOMMatrix

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨January 2020⁩.

Note: This feature is available inWeb Workers.

TheDOMMatrix interface represents 4×4 matrices, suitable for 2D and 3D operations including rotation and translation. It is a mutable version of theDOMMatrixReadOnly interface.The interface is available insideweb workers.

WebKitCSSMatrix andSVGMatrix are aliases toDOMMatrix.

DOMMatrixReadOnly DOMMatrix

Constructor

DOMMatrix()

Creates and returns a newDOMMatrix object.

Instance properties

This interface inherits properties fromDOMMatrixReadOnly, 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, wherem11 throughm14 are the first column,m21 throughm24 are the second column, and so forth.

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 equivalent
am11
bm12
cm21
dm22
em41
fm42

Instance methods

This interface includes the following methods, as well as the methods it inherits fromDOMMatrixReadOnly.

DOMMatrix.invertSelf()

Modifies the matrix by inverting it. If the matrix can't be inverted, its components are all set toNaN, andis2D returnsfalse.

DOMMatrix.multiplySelf()

Modifies the matrix by post-multiplying it with the specifiedDOMMatrix. This is equivalent to the dot productA⋅B, where matrixA is the source matrix andB is the matrix given as an input to the method. Returns itself.

DOMMatrix.preMultiplySelf()

Modifies the matrix by pre-multiplying it with the specifiedDOMMatrix. Returns itself.

DOMMatrix.translateSelf()

Modifies the matrix by applying the specified vector. The default vector is[0, 0, 0]. Returns itself.

DOMMatrix.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 is1 for all three axes, and the origin is(0, 0, 0). Returns itself.

DOMMatrix.scale3dSelf()

Modifies the matrix by applying the specified scaling factor to all three axes, centered on the given origin. Returns itself.

DOMMatrix.rotateSelf()

Modifies the matrix by rotating itself around each axis by the specified number of degrees. Returns itself.

DOMMatrix.rotateAxisAngleSelf()

Modifies the matrix by rotating it by the specified angle around the given vector. Returns itself.

DOMMatrix.rotateFromVectorSelf()

Modifies the matrix by rotating it by the angle between the specified vector and(1, 0). Returns itself.

DOMMatrix.setMatrixValue()

Replaces the contents of the matrix with the matrix described by the specified transform or transforms. Returns itself.

DOMMatrix.skewXSelf()

Modifies the matrix by applying the specified skew transformation along the X-axis. Returns itself.

DOMMatrix.skewYSelf()

Modifies the matrix by applying the specified skew transformation along the Y-axis. Returns itself.

Static methods

This interface inherits methods fromDOMMatrixReadOnly.

fromFloat32Array()

Creates a new mutableDOMMatrix object given an array of single-precision (32-bit) floating-point values. If the array has six values, the result is a 2D matrix; if the array has 16 values, the result is a 3D matrix. Otherwise, aTypeError exception is thrown.

fromFloat64Array()

Creates a new mutableDOMMatrix object given an array of double-precision (64-bit) floating-point values. If the array has six values, the result is a 2D matrix; if the array has 16 values, the result is a 3D matrix. Otherwise, aTypeError exception is thrown.

fromMatrix()

Creates a new mutableDOMMatrix object given an existing matrix or an object which provides the values for its properties.

Usage notes

The matrix defined by theDOMMatrix 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:

[m11m21m31m41m12m22m32m42m13m23m33m43m14m24m34m44]\left [ \begin{matrix} m_{11} & m_{21} & m_{31} & m_{41} \\ m_{12} & m_{22} & m_{32} & m_{42} \\ m_{13} & m_{23} & m_{33} & m_{43} \\ m_{14} & m_{24} & m_{34} & m_{44} \end{matrix} \right ]

TheDOMMatrix interface is designed with the intent that it will be used for all matrices within markup.

Specifications

Specification
Geometry Interfaces Module Level 1
# DOMMatrix

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp