
Curve Interpolator
A lib for interpolating values over a cubic Cardinal/Catmull-Rom spline curve of n-dimenesions.
Installation
npm install --save curve-interpolator
Basic usage
Reference the CurveInterpolator class:
const CurveInterpolator = require('curve-interpolator').CurveInterpolator;
import { CurveInterpolator } from 'curve-interpolator';
Define controlpoints you want the curve to pass through and pass it to the constructor of the CurveInterpolator to create an instance:
const points = [
[0, 4],
[1, 2],
[3, 6.5],
[4, 8],
[5.5, 4],
[7, 3],
[8, 0],
...
];
const interp = new CurveInterpolator(points, { tension: 0.2 });
const position = 0.3
const pt = interp.getPointAt(position)
const segments = 1000;
const pts = interp.getPoints(segments);
const axis = 1;
const yintersects = interp.lookup(7, axis);
const axis = 0;
const max = -1;
const xintersects = interp.lookup(3.2, axis, max);
const bbox = interp.getBoundingBox();
Online example on ObservableHQ:
Docs
Docs are generated using typedoc in ./docs
. To create:
npm run docs
Online: https://kjerandp.github.io/curve-interpolator/
License
MIT