Kind: global class
Npmpackage:
- Matrix2D
- new Matrix2D()
- .clear()
- .rotate(radians) ⇒
Matrix2D
- .rotate(x, y) ⇒
Matrix2D
- .skew(ax, ay) ⇒
Matrix2D
- .translate(x, y) ⇒
Matrix2D
- .getCss() ⇒
String
- .getX() ⇒
Number
- .getY() ⇒
Number
- .setFromCss(matrixString)
A 2D Matrix for transforming: translating, rotating, scaling, skewing
Import from ad-geom
Example
import { Matrix2D } from 'ad-geom'
const myMatrix = new Matrix2D()
myMatrix.rotate(0.785) // rotate 45 degrees
myMatrix.translate(30, 45) // x:30, y:45
// get the matrix as a css string to assign to style.tranform
const cssString = myMatrix.getCss() // "matrix(0.7071, 0.7071, -0.7071, 0.7071, 30, 45)"
// or get the transfrom from an element and apply to the matrix
const fromElemString = myDiv.style.transform // 'matrix(1,0,0,1,0,0)'
myMatrix.setFromCss(fromElemString)
Resets the matrix back to the identity starting point
Kind: static method of Matrix2D
Matrix2D.rotate(radians) ⇒ Matrix2D
Rotates the matrix
Kind: static method of Matrix2D
Param | Type | Description |
---|---|---|
radians | number |
The amount to rotate the matrix in radians |
Matrix2D.rotate(x, y) ⇒ Matrix2D
Scale the matrix
Kind: static method of Matrix2D
Param | Type | Description |
---|---|---|
x | number |
The amount to scale the matrix horizontally |
y | number |
The amount to scale the matrix vertically |
Matrix2D.skew(ax, ay) ⇒ Matrix2D
Skew the matrix.
Kind: static method of Matrix2D
Param | Type | Description |
---|---|---|
ax | number |
The amount to skew / slant the matrix horizontally |
ay | number |
The amount to skew / slant the matrix vertically |
Matrix2D.translate(x, y) ⇒ Matrix2D
Move the matrix's position
Kind: static method of Matrix2D
Param | Type | Description |
---|---|---|
x | number |
The amount to move the matrix horizontally |
y | number |
The amount to move the matrix vertically |
Retrieves the matrix information as a css tranfrom formatted string
Kind: static method of Matrix2D
Example
myMatrix.getCss() // matrix(1,0,0,1,0,0)
Shorthand to retrieve the matrix's x position
Kind: static method of Matrix2D
Shorthand to retrieve the matrix's y position
Kind: static method of Matrix2D
Assign the matrix's values based on existing css string
Kind: static method of Matrix2D
Param | Type | Description |
---|---|---|
matrixString | string |
A css transfrom formatted string |
Example
myMatrix.setFromCss('matrix(1,0,0,1,0,0)')