An implementation of a matrix that represents an affine transformation and works with Point.
Implements
Inheritance Hierarchy
Remarks
The matrix is interpreted row-major. The rows are defined as follows: [ m11 m12 dx ], [ m21 m22 dy ], ([ 0 0 1 ] implicitly).
When transforming a vector v using this matrix, the multiplication is done in this order: v' = M v.
MatrixOrder.PREPENDing a matrix T to this instance results in the operation M′ = M T. In concept, this means that T is applied before M when applying M' to a vector. MatrixOrder.APPENDing T to M results in M′ = T M.
Members
No filters for this type
Constructors
Parameters
- m11: number
- The value in the first row and first column of the matrix, representing the x scaling factor.
- m12: number
- The value in the first row and second column of the matrix, representing the x shear factor.
- m21: number
- The value in the second row and first column of the matrix, representing the y shear factor.
- m22: number
- The value in the second row and second column of the matrix, representing the y scaling factor.
- dx: number
- The value in the first row and third column of the matrix, representing the x translation (offset).
- dy: number
- The value in the second row and third column of the matrix, representing the y translation (offset).
Properties
Methods
Applies this matrix to the given HTML canvas rendering context.
Applies this matrix to the given HTML canvas rendering context.
final
Parameters
- ctx: CanvasRenderingContext2D
- The context to transform.
Applies this matrix to the given SVG element.
Applies this matrix to the given SVG element.
final
Parameters
- element: SVGElement
- The element to transform.
Applies this matrix to the given HTML element.
Applies this matrix to the given HTML element.
This applies position absolute, transform-origin top left, and applies this transform matrix.
final
Parameters
- element: HTMLElement
- The element to transform.
Transforms the four corner points of the given rectangle and returns the bounds of the transformed points.
Transforms the four corner points of the given rectangle and returns the bounds of the transformed points.
Create a clone of this object.
Create a clone of this object.
final
Parameters
- other: Matrix | null
- The object to compare
thisto. Must be of the same type.
Return Value
- boolean
trueifthishas the same values like the other object.
final
Parameters
- matrix: Matrix
- The matrix to multiply with this one.
- order?: MatrixOrder
- The order of the multiplication. MatrixOrder.PREPEND if not specified.
final
Parameters
- theta: number
- The rotation angle in radians
- order?: MatrixOrder
- Whether to append or prepend the rotation matrix.
final
Parameters
- theta: number
- The rotation angle in radians
- center: Point
- The center of the rotation.
- order?: MatrixOrder
- Whether to append or prepend the rotation matrix.
final
Parameters
- x: number
- The x-axis scaling factor.
- y: number
- The y-axis scaling factor.
- order?: MatrixOrder
- The order in which the scaling should be applied. The default is MatrixOrder.PREPEND.
final
Parameters
- matrix: Matrix
- The matrix to get the values from.
final
Parameters
- m0: number
- The value for M11.
- m1: number
- The value for M12.
- m2: number
- The value for M21.
- m3: number
- The value for M22.
- dx: number
- Translation in x-direction.
- dy: number
- Translation in y-direction.
Converts the Matrix object to a CSS transform.
Converts the Matrix object to a CSS transform.
The returned string can be used in a transform property.
final
Return Value
- string
- The transform string
Converts the Matrix object to an SVG transform string.
Converts the Matrix object to an SVG transform string.
The returned string can be used in a transform attribute.
final
Return Value
- string
- The transform string
Transforms the given coordinate.
Transforms the given coordinate.
final
Parameters
- point: Point
- The coordinate to transform.
Return Value
- Point
- The transformed coordinates.
Transforms the given point in place.
Transforms the given point in place.
final
Parameters
- delta: Point
- The translation delta.
- order?: MatrixOrder
- The order in which the translation should be applied. The default is MatrixOrder.PREPEND.
Constants
Static Methods
Creates a matrix rotation instance around the origin.
Creates a matrix rotation instance around the origin.
Creates a transformation matrix that can be used to transform points that are in the local coordinate system of the oriented rectangle if the top-left corner is the origin.
Creates a transformation matrix that can be used to transform points that are in the local coordinate system of the oriented rectangle if the top-left corner is the origin.
static
Parameters
- rectangle: IOrientedRectangle
- The oriented rectangle to use for defining the coordinate space.
Return Value
- Matrix
- A matrix that can be used to transform from oriented rectangle coordinates to world coordinates.
static
Parameters
- matrix: Matrix
- The matrix to use for the transformation.
- vector: Point
- The vector to transform.
Return Value
- Point
- The result of the transformation.
Examples
const v = new Point(2, 5)
// Make the vector three times as long
const longer = v.multiply(3)
console.log(longer) // (6, 15)
// Make the vector half as long
const shorter = v.multiply(0.5)
console.log(shorter) // (1, 2.5)
// Translate and scale the vector via a matrix
const matrix = new Matrix()
matrix.scale(2, 1.5)
matrix.translate(new Point(5, -3))
// ... or the transform method on Matrix
const p = new Point(7, 2)
const transformed = matrix.transform(p)
console.log(transformed) // (24, -1.5)