Skip to content

@web-engine-dev/math


@web-engine-dev/math / Mat3

Class: Mat3 ​

A 3x3 matrix stored in column-major order. Immutable by design - all operations return new instances.

Memory layout (column-major): | m0 m3 m6 | | m1 m4 m7 | | m2 m5 m8 |

Column vectors: [m0,m1,m2], [m3,m4,m5], [m6,m7,m8]

Example ​

ts
// 2D rotation and translation
const rotation = Mat3.rotation(Math.PI / 4);  // 45 degrees
const translation = Mat3.translation(10, 20);
const combined = translation.mulMat(rotation);
const transformed = combined.mulVec2Point(point);

Constructors ​

Constructor ​

new Mat3(data?): Mat3

Parameters ​

data? ​

ArrayLike<number>

Returns ​

Mat3

Methods ​

add() ​

add(m): Mat3

Parameters ​

m ​

Mat3

Returns ​

Mat3


copyMut() ​

copyMut(other): this

Copies another matrix into this matrix.

Parameters ​

other ​

Mat3

Source matrix

Returns ​

this

this for chaining


copyToArray() ​

copyToArray(arr, offset?): void

Parameters ​

arr ​

number[] | Float32Array<ArrayBufferLike>

offset? ​

number = 0

Returns ​

void


determinant() ​

determinant(): number

Returns ​

number


equals() ​

equals(m, epsilon?): boolean

Parameters ​

m ​

Mat3

epsilon? ​

number = 0

Returns ​

boolean


get() ​

get(row, col): number

Parameters ​

row ​

number

col ​

number

Returns ​

number


getColumn() ​

getColumn(col): Vec3

Parameters ​

col ​

number

Returns ​

Vec3


getRotationScale() ​

getRotationScale(): Mat3

Extract the upper-left 2x2 scale/rotation part.

Returns ​

Mat3


getRow() ​

getRow(row): Vec3

Parameters ​

row ​

number

Returns ​

Vec3


invert() ​

invert(): Mat3 | null

Returns ​

Mat3 | null


invertMut() ​

invertMut(): Mat3 | null

Inverts this matrix in place.

Returns ​

Mat3 | null

this for chaining, or null if matrix is singular


mul() ​

mul(s): Mat3

Parameters ​

s ​

number

Returns ​

Mat3


mulMat() ​

mulMat(m): Mat3

Matrix-matrix multiplication (this * m).

Parameters ​

m ​

Mat3

Returns ​

Mat3


mulVec2Direction() ​

mulVec2Direction(v): Vec2

Transform a Vec2 as a direction (z=0).

Parameters ​

v ​

Vec2

Returns ​

Vec2


mulVec2Point() ​

mulVec2Point(v): Vec2

Transform a Vec2 as a point (z=1) and divide by resulting z. Returns a large vector if w is near zero to avoid Infinity/NaN.

Parameters ​

v ​

Vec2

Returns ​

Vec2


mulVec3() ​

mulVec3(v): Vec3

Transform a Vec3 by this matrix.

Parameters ​

v ​

Vec3

Returns ​

Vec3


setFromArrayMut() ​

setFromArrayMut(arr, offset?): this

Sets this matrix from an array (column-major order).

Parameters ​

arr ​

ArrayLike<number>

Source array

offset? ​

number = 0

Start offset in array

Returns ​

this

this for chaining


setIdentityMut() ​

setIdentityMut(): this

Sets this matrix to the identity matrix.

Returns ​

this

this for chaining


setMut() ​

setMut(m0, m1, m2, m3, m4, m5, m6, m7, m8): this

Sets all 9 elements of this matrix directly (column-major order).

Parameters ​

m0 ​

number

Column 0, row 0

m1 ​

number

Column 0, row 1

m2 ​

number

Column 0, row 2

m3 ​

number

Column 1, row 0

m4 ​

number

Column 1, row 1

m5 ​

number

Column 1, row 2

m6 ​

number

Column 2, row 0

m7 ​

number

Column 2, row 1

m8 ​

number

Column 2, row 2

Returns ​

this

this for chaining


sub() ​

sub(m): Mat3

Parameters ​

m ​

Mat3

Returns ​

Mat3


toArray() ​

toArray(): number[]

Returns ​

number[]


toFloat32Array() ​

toFloat32Array(): Float32Array

Returns ​

Float32Array


toString() ​

toString(): string

Returns ​

string


transpose() ​

transpose(): Mat3

Returns ​

Mat3


transposeMut() ​

transposeMut(): this

Transposes this matrix in place.

Returns ​

this

this for chaining


fromArray() ​

static fromArray(arr, offset?): Mat3

Parameters ​

arr ​

ArrayLike<number>

offset? ​

number = 0

Returns ​

Mat3


fromColumns() ​

static fromColumns(c0, c1, c2): Mat3

Parameters ​

c0 ​

Vec3

c1 ​

Vec3

c2 ​

Vec3

Returns ​

Mat3


fromRows() ​

static fromRows(r0, r1, r2): Mat3

Parameters ​

r0 ​

Vec3

r1 ​

Vec3

r2 ​

Vec3

Returns ​

Mat3


identity() ​

static identity(): Mat3

Returns ​

Mat3


rotation() ​

static rotation(angle): Mat3

Creates a 2D rotation matrix (rotation around Z).

Parameters ​

angle ​

number

Rotation angle in radians.

Returns ​

Mat3


scaling() ​

static scaling(sx, sy): Mat3

Creates a 2D scale matrix.

Parameters ​

sx ​

number

sy ​

number

Returns ​

Mat3


translation() ​

static translation(tx, ty): Mat3

Creates a 2D translation matrix.

Parameters ​

tx ​

number

ty ​

number

Returns ​

Mat3


zero() ​

static zero(): Mat3

Returns ​

Mat3

Proprietary software. All rights reserved.