An implementation of a matrix that represents an affine transformation and works with Point.
Implements
- I
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.
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. 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.
Applies this matrix to the given SVG element.
Applies this matrix to the given SVG element.
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.
Create a clone of this object.
Create a clone of this object.
Determines whether this has the same values like other.
Determines whether
this has the same values like other.final
Parameters
- other: Matrix
- The object to compare
thisto. Must be of the same type.
Return Value
- boolean
trueifthishas the same values like the other object.
Multiplies this matrix instance by the given instance using the given order.
Multiplies this matrix instance by the given instance using the given order.
final
Parameters
- matrix: Matrix
- The matrix to multiply with this one.
- order?: MatrixOrder
- The order of the multiplication. PREPEND if not specified.
Prepends or appends a rotation operation to this matrix around the origin.
Prepends or appends a rotation operation to this matrix around the origin.
final
Parameters
- theta: number
- The rotation angle in radians
- order?: MatrixOrder
- Whether to append or prepend the rotation matrix.
Prepends or appends a rotation operation to this matrix around the specified rotation center.
Prepends or appends a rotation operation to this matrix around the specified rotation center.
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.
Appends or prepends a scale operation to this instance.
Appends or prepends a scale operation to this instance.
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 PREPEND.
Sets the values of the given matrix to this instance.
Sets the values of the given
matrix to this instance.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 point in place.
Transforms the given point in place.
Appends or Prepends a translation to this instance.
Appends or Prepends a translation to this instance.
final
Parameters
- delta: Point
- The translation delta.
- order?: MatrixOrder
- The order in which the translation should be applied. The default is 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
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)