JavaScript implementation of
CoffeeScript implementation of
Python implementation of
Algorithm for Automatically Fitting Digitized Curves
by Philip J. Schneider
"Graphics Gems", Academic Press, 1990
- Include the JavaScript file.
If you included fitCurves.js
or fitCurves3D.js
- Call
fitCurves(a,e)
with an array of points to fit a curve to, and a non-negative number for how close of an approximation you want (smaller numbers giving a more accurate result). - The function will return an array of arrays of the four points required to plot a cubic Bézier curve.
If you included fitCurvesAlt.js
- Call
fitCurves(a)
with an array of points to fit a curve to. - The function will return a single array of the four points required to plot a cubic Bézier curve.
A 'point' is just an array of two numbers (or three numbers for the 3D version).
This code was originally committed as part of a different repository on February 28, 2016. Back then I didn't use GitHub as much, so I didn't bother uploading it in its own repository. The history of this repository up to version 3 (8c85212) was recreated from changes made in that repository.
Currently our forks are essentially the same. The main differences being that mine just has the JavaScript files (not having an online demo or being NPM/Bower compatible), and that I have two alternate versions. One that works in three dimensions, and one that returns the point for a single curve rather than an array of curves. Also mine is quite a bit smaller and more self-contained.