Skip to content

Class: Matrix2D ​

3×3 affine 2D matrix in column-major order, stored as 6 numbers (a, b, c, d, tx, ty):

| a c tx | | b d ty | | 0 0 1 |

Convention matches Pixi / Canvas2D / WebGL2 column-major affine matrices so passing values across the boundary is one assignment per field. Operations mutate this and return this for chaining; use Clone()/static *Of variants when a fresh matrix is needed.

Apply order in Identity().Translate(t).Rotate(r).Scale(s) reads as "translate, then rotate, then scale" when expressed as M * v (standard math convention).

Constructors ​

Constructor ​

ts
new Matrix2D(
   a?, 
   b?, 
   c?, 
   d?, 
   tx?, 
   ty?
): Matrix2D;

Parameters ​

ParameterTypeDefault value
anumber1
bnumber0
cnumber0
dnumber1
txnumber0
tynumber0

Returns ​

Matrix2D

Properties ​

PropertyModifierType
apublicnumber
bpublicnumber
cpublicnumber
dpublicnumber
txpublicnumber
typublicnumber

Methods ​

ApplyToPoint() ​

ts
ApplyToPoint(
   x, 
   y, 
   out
): void;

Apply this matrix to a point (x, y) and write the result into out.

Parameters ​

ParameterType
xnumber
ynumber
out{ x: number; y: number; }
out.xnumber
out.ynumber

Returns ​

void


Clone() ​

ts
Clone(): Matrix2D;

Returns ​

Matrix2D


Copy() ​

ts
Copy(m): this;

Parameters ​

ParameterType
mMatrix2D

Returns ​

this


FromTRS() ​

ts
static FromTRS(
   tx, 
   ty, 
   rotation, 
   sx, 
   sy
): Matrix2D;

Build from translation/rotation/scale (TRS) — useful for composing a world transform.

Parameters ​

ParameterType
txnumber
tynumber
rotationnumber
sxnumber
synumber

Returns ​

Matrix2D


Identity() ​

ts
static Identity(): Matrix2D;

Returns ​

Matrix2D


Identity() ​

ts
Identity(): this;

Returns ​

this


Invert() ​

ts
Invert(): this;

Invert in place. Safe to call when the matrix is singular — leaves identity.

Returns ​

this


Multiply() ​

ts
Multiply(m, out?): Matrix2D;

out = this * m. Pass this as out for in-place multiply.

Parameters ​

ParameterType
mMatrix2D
outMatrix2D

Returns ​

Matrix2D


Rotate() ​

ts
Rotate(radians): this;

Right-multiply: this = this * (rotation matrix).

Parameters ​

ParameterType
radiansnumber

Returns ​

this


Scale() ​

ts
Scale(sx, sy): this;

Right-multiply: this = this * (scale matrix).

Parameters ​

ParameterType
sxnumber
synumber

Returns ​

this


Set() ​

ts
Set(
   a, 
   b, 
   c, 
   d, 
   tx, 
   ty
): this;

Parameters ​

ParameterType
anumber
bnumber
cnumber
dnumber
txnumber
tynumber

Returns ​

this


Translate() ​

ts
Translate(x, y): this;

Right-multiply: this = this * (translation matrix).

Parameters ​

ParameterType
xnumber
ynumber

Returns ​

this

© 2026 PlayAdGentic