Skip to main content

Class: MatrixTracker

Defined in: src/interaction/DynamicMatrix.ts:134

MatrixTracker — holds a live 2x2 matrix, the matrix analogue of ValueTracker.

It either stores a matrix directly (via the constructor or setMatrix) or computes one on every read from a getter (fromGetter) or from two basis-vector sources (fromBasisVectors). Bind it to a grid with applyMatrixLive.

Example​

const iPoint = new MovablePoint(scene, { point: [1, 0, 0] });
const jPoint = new MovablePoint(scene, { point: [0, 1, 0] });
const tracker = MatrixTracker.fromBasisVectors(iPoint, jPoint);
applyMatrixLive(plane, tracker, { onChange: () => scene.render() });

Constructors​

Constructor​

new MatrixTracker(matrix): MatrixTracker

Defined in: src/interaction/DynamicMatrix.ts:142

Create a tracker holding a fixed matrix.

Parameters​

matrix​

Matrix2x2 = ...

The initial matrix. Default: the identity.

Returns​

MatrixTracker

Methods​

getColumns()​

getColumns(): [[number, number], [number, number]]

Defined in: src/interaction/DynamicMatrix.ts:183

Get the two column basis vectors [i, j] of the current matrix.

Returns​

[[number, number], [number, number]]

[i, j] where i = (a, c) and j = (b, d).


getMatrix()​

getMatrix(): Matrix2x2

Defined in: src/interaction/DynamicMatrix.ts:151

Get the current matrix as a fresh copy.

Returns​

Matrix2x2

The current matrix.


setColumns()​

setColumns(i, j): this

Defined in: src/interaction/DynamicMatrix.ts:172

Set the matrix from its two column basis vectors.

Parameters​

i​

readonly [number, number]

The image of the x basis vector, (a, c).

j​

readonly [number, number]

The image of the y basis vector, (b, d).

Returns​

this

this for chaining.


setMatrix()​

setMatrix(matrix): this

Defined in: src/interaction/DynamicMatrix.ts:160

Set the matrix directly, dropping any getter source.

Parameters​

matrix​

Matrix2x2

The new matrix.

Returns​

this

this for chaining.


transformPoint()​

transformPoint(point): [number, number]

Defined in: src/interaction/DynamicMatrix.ts:196

Map a 2D point by the current matrix (about the origin).

Parameters​

point​

readonly [number, number]

The point [x, y] to transform.

Returns​

[number, number]

The transformed point [x', y'].


fromBasisVectors()​

static fromBasisVectors(iSource, jSource): MatrixTracker

Defined in: src/interaction/DynamicMatrix.ts:220

Create a tracker whose matrix is built live from two basis-vector sources. The columns follow the sources, so dragging a MovablePoint drives the matrix in real time.

Parameters​

iSource​

BasisVectorSource

Source of the x basis vector image (first column).

jSource​

BasisVectorSource

Source of the y basis vector image (second column).

Returns​

MatrixTracker

A new MatrixTracker.


fromGetter()​

static fromGetter(getter): MatrixTracker

Defined in: src/interaction/DynamicMatrix.ts:206

Create a tracker whose matrix is recomputed from a getter on every read.

Parameters​

getter​

() => Matrix2x2

Returns the current matrix.

Returns​

MatrixTracker

A new MatrixTracker.