Skip to main content

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

NAMETYPE
matrixMatrix

multiply

multiply(a, b);

Returns a multiplied by b

Parameters

NAMETYPE
aMatrix
bMatrix

fromPosition

fromPosition(position);

Create a new transformation matrix from a position

Returns a Matrix

Parameters

NAMETYPE
positionVector2

fromRotation

fromRotation(rotation);

Create a new transformation matrix from a rotation

Returns a Matrix

Parameters

NAMETYPEDESCRIPTION
rotationnumberRotation in degrees

fromScale

fromScale(scale);

Create a new transformation matrix from a scale

Returns a Matrix

Parameters

NAMETYPE
scaleVector2

fromItem

fromItem(item);

Create a new transformation matrix from a Item

Returns a Matrix

Parameters

NAMETYPE
itemItem

decompose

decompose(matrix);

Decompose a matrix into its individual parts

Returns the position, scale and rotation (in degrees) of the matrix

Parameters

NAMETYPE
matrixMatrix