An OpenFrameworks addon for obtaining a Bezier curve through a set of points, based on Paper.js path simplification
README
ofxPathFitter
Introduction
An OpenFrameworks addon for obtaining a Bezier curve through a set of pointsBased on Paper.js path simplification
Installation
Just drop the folder into theopenFrameworks/addons/ folder.Example
See SimpleVectorEditor, which uses this addon to simplify the lines that are drawn.<img src="img/edit.png" width="400">
Usage
ofPolyline line = ... vector<ofPoint> vertices = line.getVertices(); // the set of points bool closed = false; double tolerance = 10; vector<BezPoint> bezier = ofxPathFitter::simplify(vertices, closed, tolerance); // creates the Bezier curve through the points orbezier = ofxPathFitter::simplify(line, tolerance);
BezPoint contains 3 fields:
ofPoint point; // the point ofPoint handleIn; // the first control point ofPoint handleOut // the second control point
Note: the control points contain the coordinates relative to the point. To get the absolute coordinates:
BezPoint s = ofxPathFitter::handlesAbsolute(bezier[i]);
or
vector<BezPoint> bezierAbs = ofxPathFitter::handlesAbsolute(bezier);
ofxAddons