Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thibauts/cubic-hermite-spline
Cubic Hermite spline interpolation
https://github.com/thibauts/cubic-hermite-spline
Last synced: about 2 months ago
JSON representation
Cubic Hermite spline interpolation
- Host: GitHub
- URL: https://github.com/thibauts/cubic-hermite-spline
- Owner: thibauts
- License: mit
- Created: 2015-03-19T22:41:26.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-20T08:26:54.000Z (almost 10 years ago)
- Last Synced: 2024-10-30T06:27:06.705Z (about 2 months ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 44
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
cubic-hermite-spline
====================
### Cubic Hermite spline interpolation[Cubic Hermite spline](http://en.wikipedia.org/wiki/Cubic_Hermite_spline) interpolation of points / tangents in any dimension with optional derivative computation. The interpolator can also take a knot-like vector as an optional parameter, which may be useful to enforce time at control points when used for position / velocity interpolation.
Install
-------```bash
$ npm install cubic-hermite-spline
```Example
-------Basic usage
```javascript
var hermite = require('cubic-hermite-spline');var points = [
[-1, 0],
[ 0, 0],
[ 1, 0]
];var tangents = [
[1, 1],
[0, 1],
[1, 1]
];for(var t=0; t<1; t+=0.01) {
var point = hermite(t, points, tangents);
var tangent = hermite(t, points, tangents, null, true);
}
```With a knot vector
```javascript
var hermite = require('cubic-hermite-spline');var points = [
[-1, 0],
[ 0, 0],
[ 1, 0]
];var tangents = [
[1, 1],
[0, 1],
[1, 1]
];var knots = [
0, 1.5, 2
];for(var t=0; t<1; t+=0.01) {
var point = hermite(t, points, tangents);
var tangent = hermite(t, points, tangents, knots, true);
}
```Usage
-----### `hermite(t, points, tangents[, knots, derivative, result])`
Computes the interpolation at `t` for the provided set of points and tangents, and optional knots.
* `t` position along the curve: in the [0, 1] range for regular use, and [0, last-knot-value] when using knots
* `points` vectors to interpolate
* `tangents` tangents at provided points
* `knots` enforced values of `t` at provided points
* `derivative` if true return the tangeant at `t` instead of the position
* `result` preallocated array in which the result will be stored (to avoid garbage collection)**Returns** the interpolated vector