Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 914 Bytes

README.md

File metadata and controls

29 lines (22 loc) · 914 Bytes

Fit one or more cubic Bezier curves to a polyline. JavaScript implementation of Philip J. Schneider's "Algorithm for Automatically Fitting Digitized Curves" from the book "Graphics Gems".

Ported from C via Python:

No dependencies.

Usage

var points = [[0, 0], [10, 10], [10, 0], [20, 0]];
var error = 50;  // Lower numbers give more accurate curves

var bezierCurves = fitCurve(points, error);
// bezierCurves[0] === [[0, 0], [20.27317402, 20.27317402], [-1.24665147, 0], [20, 0]]
// where each element is [x, y] and elements are [first-point, control-point-1, control-point-2, second-point] 

Demo

http://codepen.io/Sphinxxxx/pen/jALxvQ?editors=1011