Skip to main content

@math.gl/core/matrix

This entry point exposes the foundational core math API, including vectors, matrices, quaternions, Euler rotations, poses, coordinate conversions, numeric types, and utilities.

Usageโ€‹

import {Vector2} from '@math.gl/core/matrix';
const vector = new Vector2(1, 2);
const x = vector[0];
const y = vector[1];

Featuresโ€‹

FeatureSupportNotes
Vectors and small dense matricesโœ…Vector2/3/4 and Matrix3/4, with mutable array-compatible storage.
Quaternion and Euler rotationsโœ…Quaternions, Euler angles, interpolation, and rotation-order conventions.
Rigid poses and local framesโœ…Pose and local frames; units and coordinate conventions remain explicit.
Spherical and spheroid coordinatesโœ…SphericalCoordinates and spheroid conversions within their documented shape domains.
Reusable outputs and numeric interoperabilityโœ…MathArray operations interoperate with arrays and typed arrays; individual methods document ownership.
General dense/sparse linear algebraโŒNo public general-size QR/SVD, sparse factorization, or tensor engine. The matrix classes target graphics-sized transforms.
Arbitrary-precision arithmetic and autodifferentiationโŒNumerical classes use JavaScript numbers; no arbitrary-precision scalar or gradient-tape backend.
Built-in SIMD, WASM, or GPU numeric backendโŒCPU JavaScript math is implemented; accelerated numerical backends remain roadmap research. Worker scheduling is a separate capability.

Core transformsโ€‹

Loading Core transformsโ€ฆ

Open the interactive example.

Installationโ€‹

npm install @math.gl/core

Classesโ€‹

ClassDescription
Vector2Two element vector, inherits from Array
Vector3Three element vector, inherits from Array
Vector4Four element vector, inherits from Array
Matrix33x3 matrix, inherits from Array
Matrix44x4 matrix, inherits from Array
QuaternionQuaternion in [x,y,z,w] form, inherits from Array
PosePosition and orientation with transformation matrices
Euler3 Euler angles and rotation order
SphericalCoordinates2 rotations and a radius

Conventionsโ€‹

  • Arithmetic methods usually mutate the receiver and return it. Clone an object before modifying it when the original is needed.
  • Vector components are accessible by index and by name, such as vector[0] and vector.x.
  • Matrices store elements in column-major order. Rotations use radians; Euler orders are lowercase strings.
  • Matrix transform methods allocate a result array unless an output is supplied. See performance for reuse patterns.
  • Enable optional validation with configure({debug: true}). See debugging for checks and formatting.

Numeric helpers and sample tracksโ€‹

Numeric helpers cover vector projection/reflection, length controls, scalar damping and quaternion stepping. SampleTrack evaluates timestamped scalar, vector and quaternion samples with reusable outputs.

Learn core mathโ€‹

Start with transformations and 3D rotations. The guides also cover coordinate systems, homogeneous coordinates, view and projection matrices, and floating point.

Numeric local framesโ€‹

The local-frame functions are named exports from @math.gl/core/matrix. They provide ENU/XYZ rotations and ENU/NED matrices with reusable outputs. Angles are explicit radians and distances retain their units.

Interoperabilityโ€‹

math.gl classes extend Array, so their components can be passed directly to array-based math APIs such as gl-matrix. Reuse vectors and matrices in hot loops to avoid repeated allocations. Low-level namespaces and individual functions are named exports from this entry point. See functional math for normal matrices, transform composition, depth conventions, and interpolation.

When interoperating with other numeric APIs:

  • Use vector.len() for magnitude; vector.length is the array's element count.
  • Matrix elements use column-major storage. Check the argument order when copying values through another library's setters.
  • Methods that depend on renderer-owned geometries or buffer attributes are outside the core API. Copy their numeric components into math.gl vectors or matrices instead.