Namespace math

xeokit SDK Math Libraries


Mathematical functions for 2D/3D matrices, quaternions, and vectors


This library provides a set of utilities for working with mathematical operations commonly used in 3D graphics, including vector and matrix operations such as dot products, vector negation, addition, and more.


  • Allocation-aware — typed Vec/Mat constructors return raw Float32Array / Float64Array typed-array views so they round-trip cleanly through GPU upload paths.
  • In-place + out-of-place variants — most ops accept an optional dest so hot-paths can reuse pre-allocated scratch.
  • Double-precision throughout — every transform / boundary math op exists in both Float32 and Float64 flavours; the Float64 path is used by the scene-graph for accurate world-scale transforms.
  • Compression helpers — quantise / dequantise positions against an AABB, oct-encode / decode normals, pack UVs against a [uMin, uMax, vMin, vMax] rect. Used by the SceneModel builder and XGF format I/O.
  • RTC (Relative-To-Centre) — tile-based world ↔ local conversions that keep GPU positions near the origin for real-world-scale models.
  • Curves — Catmull-Rom / cubic / quadratic Bézier evaluation primitives for camera-path animation.

Installation

To install the xeokit SDK, use the following npm command:

npm install @xeokit/sdk

Usage

You can import and use functions from the math module as follows:

import { dotVec3, createVec3Float64 } from "@xeokit/sdk/base/math";

const a = createVec3Float64([0.1, 1, 2.1]);
const b = createVec3Float64([0.5, 2.1, -1.3]);

const c = dotVec3(a, b); // Computes the dot product of vectors a and b

Namespaces

boundaries
compression
curves
matrix
polygon2D
quat
rtc
vector

Type Aliases

FloatArrayParam
FloatTypedArray
IntArrayParam
IntTypedArray
NumericTypedArray

Variables

DEGTORAD
MAX_DOUBLE
MAX_INT
MIN_DOUBLE
RADTODEG

Functions

canvasPosToWorldRay
clamp
clamp01
newFloatArray
rayTriangleIntersect
safeInv
transformRay