Namespace curves

xeokit Spline Curve Math Utilities


Math helpers for working with spline curves.


This module contains lightweight curve utilities for evaluating common spline types, currently focused on Bézier (quadratic/cubic) and Catmull–Rom interpolation. These functions are handy when you need smooth parametric motion, easing-like blends, or curve-based sampling in 1D, 2D, or 3D workflows (for example: camera rails, animated values, or generating polyline samples).

All evaluators use a normalized parameter t in the range [0..1].

npm install @xeokit/sdk

Below are examples of a few commonly used helpers.

Import the functions:

import {
tangentQuadraticBezier,
tangentQuadraticBezier3,
tangentSpline,
catmullRomInterpolate,
b2,
b3
} from "@xeokit/sdk/math/curves";
const t = 0.5; // 0 ≤ t ≤ 1
const p0 = 0, p1 = 10, p2 = 20; // Control points
const tangentQuad = tangentQuadraticBezier(t, p0, p1, p2);
console.log("Quadratic Bézier tangent:", tangentQuad);
const p3 = 30; // Fourth control point
const tangentCubic = tangentQuadraticBezier3(t, p0, p1, p2, p3);
console.log("Cubic Bézier tangent:", tangentCubic);
const tangentSplineValue = tangentSpline(t);
console.log("Spline tangent basis:", tangentSplineValue);
const interpolatedValue = catmullRomInterpolate(p0, p1, p2, p3, t);
console.log("Catmull–Rom interpolation:", interpolatedValue);
const quadBezierResult = b2(t, p0, p1, p2);
console.log("Quadratic Bézier value:", quadBezierResult);
const cubicBezierResult = b3(t, p0, p1, p2, p3);
console.log("Cubic Bézier value:", cubicBezierResult);

Functions

b2
b2p0
b2p1
b2p2
b3
b3p0
b3p1
b3p2
b3p3
catmullRomInterpolate
tangentQuadraticBezier
tangentQuadraticBezier3
tangentSpline