cat-rom-spline
Version:
Catmull Rom spline interpolation made easy.
48 lines (32 loc) • 1.22 kB
Markdown
```sh
$ npm install --save cat-rom-spline
```
```js
var catRomSpline = require('cat-rom-spline');
// Points are arrays in the form of [x, y]
var p0 = [0, 0];
var p1 = [5, 5];
var p2 = [5, 10];
var p3 = [15, 20];
// At least 4 points are needed to interpolate
var points = [p0, p1, p2, p3];
// There are optional configurations that you can make but they aren't required
// If 'samples' is not passed in the interpolation will sample a sensible amount
// of points based on how far away control points are
var options = {
samples: 50,
knot: 0.5 // Default is 0.5, Ranges from 0 - 1, 1 being stiffer curves.
};
var interpolatedPoints = catRomSpline(points, options);
```
MIT © [Nick Schaubeck](http://www.northofbrooklyn.nyc)
[]: https://badge.fury.io/js/cat-rom-spline.svg
[]: https://npmjs.org/package/cat-rom-spline
[]: https://travis-ci.org/nschaubeck/cat-rom-spline.svg?branch=master
[]: https://travis-ci.org/nschaubeck/cat-rom-spline
[]: https://david-dm.org/nschaubeck/cat-rom-spline.svg?theme=shields.io
[]: https://david-dm.org/nschaubeck/cat-rom-spline