# curve-interpolator

> Interpolate values on a Cardinal/Catmull-Rom spline curve

Latest version **3.3.1** (published 2023-11-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install curve-interpolator
pnpm add curve-interpolator
yarn add curve-interpolator
bun add curve-interpolator
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.3.1 |
| Published | 2023-11-22 |
| First published | 2018-03-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 185.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 52 |
| Author | Kjerand Pedersen |
| Maintainers | kjerandp |
| Keywords | cubic, cardinial, catmull-rom, curve, interpolate, interpolator, spline, analysis |

## Links

- npm: https://www.npmjs.com/package/curve-interpolator
- Repository: https://github.com/kjerandp/curve-interpolator
- Homepage: https://github.com/kjerandp/curve-interpolator#readme
- Issues: https://github.com/kjerandp/curve-interpolator/issues
- npm.io page: https://npm.io/package/curve-interpolator

## Recent versions

- 3.3.1 (latest) — 2023-11-22
- 3.1.0-beta.6 (beta) — 2023-02-21
- 2.0.0 (next) — 2020-03-16
- 3.3.0 — 2023-09-19
- 3.2.0 — 2023-09-18
- 3.1.1 — 2023-02-24
- 3.1.0 — 2023-02-21
- 3.1.0-beta.5 — 2023-02-20
- 3.1.0-beta.4 — 2023-02-17
- 3.1.0-beta.3 — 2023-02-15
- 3.1.0-beta.2 — 2023-01-31
- 3.1.0-beta.1 — 2023-01-27
- 3.0.1 — 2023-01-10
- 3.0.0 — 2023-01-06
- 2.0.8 — 2020-06-05
- … 34 more at https://npm.io/package/curve-interpolator/versions

## README

![](https://github.com/kjerandp/curve-interpolator/workflows/Node%20CI/badge.svg)
![](https://img.shields.io/npm/v/curve-interpolator)
# Curve Interpolator

A lib for interpolating values over a cubic Cardinal/Catmull-Rom spline curve of n-dimenesions.

## Installation
```bash
npm install --save curve-interpolator
```
## Basic usage
Reference the CurveInterpolator class:
```js
// commonjs
const CurveInterpolator = require('curve-interpolator').CurveInterpolator;

// es6
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:

```js
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, alpha: 0.5 });

// get single point
const position = 0.3 // [0 - 1]
const pt = interp.getPointAt(position)

// get points evently distributed along the curve
const segments = 1000;
const pts = interp.getPoints(segments);

// lookup values along x and y axises
const axis = 1;
const yintersects = interp.getIntersects(7, axis);

/*
max number of solutions (0 = all (default), 1 = first, -1 = last)
A negative max value counts solutions from end of curve
*/
const axis = 0;
const max = -1;
const xintersects = interp.getIntersects(3.2, axis, max);

// get bounding box
const bbox = interp.getBoundingBox();
```

Online example on ObservableHQ:
- https://observablehq.com/@kjerandp/curve-interpolator-demo

## Docs
Docs are generated using typedoc in `./docs`. To create:
```bash
npm run docs
```
Online: https://kjerandp.github.io/curve-interpolator/

## License
MIT

---
_Source: https://npm.io/package/curve-interpolator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
