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
| Parameter | Type | Default value |
|---|---|---|
a | number | 1 |
b | number | 0 |
c | number | 0 |
d | number | 1 |
tx | number | 0 |
ty | number | 0 |
Returns
Matrix2D
Properties
| Property | Modifier | Type |
|---|---|---|
a | public | number |
b | public | number |
c | public | number |
d | public | number |
tx | public | number |
ty | public | number |
Methods
ApplyToPoint()
ts
ApplyToPoint(
x,
y,
out
): void;Apply this matrix to a point (x, y) and write the result into out.
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
out | { x: number; y: number; } |
out.x | number |
out.y | number |
Returns
void
Clone()
ts
Clone(): Matrix2D;Returns
Matrix2D
Copy()
ts
Copy(m): this;Parameters
| Parameter | Type |
|---|---|
m | Matrix2D |
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
| Parameter | Type |
|---|---|
tx | number |
ty | number |
rotation | number |
sx | number |
sy | number |
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
| Parameter | Type |
|---|---|
m | Matrix2D |
out | Matrix2D |
Returns
Matrix2D
Rotate()
ts
Rotate(radians): this;Right-multiply: this = this * (rotation matrix).
Parameters
| Parameter | Type |
|---|---|
radians | number |
Returns
this
Scale()
ts
Scale(sx, sy): this;Right-multiply: this = this * (scale matrix).
Parameters
| Parameter | Type |
|---|---|
sx | number |
sy | number |
Returns
this
Set()
ts
Set(
a,
b,
c,
d,
tx,
ty
): this;Parameters
| Parameter | Type |
|---|---|
a | number |
b | number |
c | number |
d | number |
tx | number |
ty | number |
Returns
this
Translate()
ts
Translate(x, y): this;Right-multiply: this = this * (translation matrix).
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns
this