Namespace curves

Spline Curve Math Functions

This module provides various mathematical functions for spline curves, including Bézier and Catmull-Rom interpolation methods. These functions are useful for generating and manipulating smooth curves in 3D and 2D space.

To install the module, run the following command:

npm install @xeokit/sdk

We'll demonstrate a selection of curve functions provided by this module.

Import the functions:

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

Functions

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