Skip to main content

Function: applyMatrixLive()

applyMatrixLive<M>(target, matrix, options): LiveMatrixBinding<M>

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

Bind a mobject to a live 2x2 or 3x3 matrix so it morphs continuously.

Every VMobject leaf in target's family is snapshotted at bind time, and so is the vertex buffer of every 3D mesh mobject (Sphere, Cube, Surface3D, ...). An updater is added to target; each frame it re-maps every snapshotted point by the current matrix (about aboutPoint) and moves any dependent points. Because the re-map always starts from the snapshot, the transform is absolute and free of per-frame drift — a collapsed (singular) matrix is just a flat shape, with full recovery on the next frame.

A 2x2 matrix maps x and y and keeps z, for a 2D scene. A 3x3 matrix maps all three axes, for a ThreeDScene.

Frame rule: every leaf is mapped in its own local frame, VMobject and mesh alike. aboutPoint is a point in that frame. An offset from moveTo, shift or a mesh's center option lives in the shape's own transform, so the shape deforms about its own center and stays where it is. An offset baked into the points (a Line from start to end, a Polygon from its vertices) is part of the local frame, so it is mapped too. A part with its own transform follows the rule on its own: an Arrow tip keeps its offset in its transform, so a shear moves it off the shaft. To map several shapes about one shared scene point, keep their transforms at the identity: build VMobjects from coordinates and leave meshes at the origin. Mesh normals follow the inverse transpose of the map, so lighting stays right under a shear.

Geometry that a mesh rebuilds after binding (for example Sphere.setRadius) is not tracked; bind again after such a change. Instanced meshes and fat 3D lines (Line3D) are skipped.

The one-shot applyMatrix is untouched; this is the additive live mode.

Type Parameters​

M​

M extends LiveMatrix = Matrix2x2

Parameters​

target​

Mobject

The grid/plane/mobject to morph (e.g. a NumberPlane or a Cube).

matrix​

MatrixSource<M>

The driving matrix, getter, or MatrixTracker.

options​

DynamicMatrixOptions<M> = {}

Pivot, dependent points and an onChange render hook.

Returns​

LiveMatrixBinding<M>

A LiveMatrixBinding controlling the binding.

Example​

const tracker = MatrixTracker.fromBasisVectors(iPoint, jPoint);
applyMatrixLive(plane, tracker, {
dependents: [{ mobject: vector, base: [2, 1, 0] }],
onChange: () => scene.render(),
});

// 3D: shear a cube along x by its height.
applyMatrixLive(cube, [[1, 0, 1], [0, 1, 0], [0, 0, 1]]);