@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โ
| Feature | Support | Notes |
|---|---|---|
| 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โฆ
Installationโ
npm install @math.gl/core
Classesโ
| Class | Description |
|---|---|
Vector2 | Two element vector, inherits from Array |
Vector3 | Three element vector, inherits from Array |
Vector4 | Four element vector, inherits from Array |
Matrix3 | 3x3 matrix, inherits from Array |
Matrix4 | 4x4 matrix, inherits from Array |
Quaternion | Quaternion in [x,y,z,w] form, inherits from Array |
Pose | Position and orientation with transformation matrices |
Euler | 3 Euler angles and rotation order |
SphericalCoordinates | 2 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]andvector.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.lengthis 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.