MathM
Math class for a 2D transformation Matrix.
Examples
Find the relative transform between two items
const a = buildShape().build();
const b = buildShape().build();
const aTransform = MathM.fromItem(a);
const bTransform = MathM.fromItem(b);
const invATransform = MathM.inverse(aTransform);
const relativeBTransform = MathM.multiply(invATransform, bTransform);
Find the world position of a line's startPosition
const line = buildLine().build();
const lineTransform = MathM.fromItem(line);
const startTransform = MathM.fromPosition(line.startPosition);
const worldTransform = MathM.multiply(lineTransform, startTransform);
const worldPosition = MathM.decompose(worldTransform).position;
Reference
Methods
inverse
inverse(matrix);
Returns the inverse of the given matrix
Parameters
| NAME | TYPE |
|---|---|
| matrix | Matrix |
multiply
multiply(a, b);
Returns a multiplied by b
Parameters
| NAME | TYPE |
|---|---|
| a | Matrix |
| b | Matrix |
fromPosition
fromPosition(position);
Create a new transformation matrix from a position
Returns a Matrix
Parameters
| NAME | TYPE |
|---|---|
| position | Vector2 |
fromRotation
fromRotation(rotation);
Create a new transformation matrix from a rotation
Returns a Matrix
Parameters
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| rotation | number | Rotation in degrees |
fromScale
fromScale(scale);
Create a new transformation matrix from a scale
Returns a Matrix
Parameters
| NAME | TYPE |
|---|---|
| scale | Vector2 |
fromItem
fromItem(item);
Create a new transformation matrix from a Item
Returns a Matrix
Parameters
| NAME | TYPE |
|---|---|
| item | Item |
decompose
decompose(matrix);
Decompose a matrix into its individual parts
Returns the position, scale and rotation (in degrees) of the matrix
Parameters
| NAME | TYPE |
|---|---|
| matrix | Matrix |