Skip to content

Library for global and incremental variants of John Hobby's curve drawing algorithm

Notifications You must be signed in to change notification settings

micycle1/Hobby-Curves

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hobby Curves

Hobby Curves, in Java.

Overview

John Hobby’s algorithm [1] produces a smooth curve through a given set of points. The curve comprises a chain of cubic Bézier curves whose endpoints pass through the points. The parameters of the Bézier curves are chosen such that they join smoothly, forming one long curve through the point set. Hobby Curves are more visually pleasing than curves produced with most other techniques.

This Java library implements both variants of the Hobby Curve: the original "global" algorithm (implementation based on Luke Trujillo's C++ implementation) and an incremental variant (implementation based on loopspace's js implementation).

Gallery

Hobby Curve (unclosed) of a point set Original (orange) vs incremental (blue) variants

Example

Global

double[][] points = new double[4][2];
points[0] = new double[] { 0.0, 0.0 };
points[1] = new double[] { 10.0, 15.0 };
points[2] = new double[] { 20.0, 0.0 };
points[3] = new double[] { 10.0, -10.0 };

double tension = 1;
double closed = true;
double beginCurl = 1;
double endCurl = 1;

HobbyCurve curve = new HobbyCurve(points, tension, closed, beginCurl, endCurl);

for (double[] bezier : curve.getBeziers()) {
	System.out.println(Arrays.toString(bezier));
}

Incremental

IncrementalHobbyCurve curve = new IncrementalHobbyCurve();

curve.addKnot(new double[] { 0.0, 0.0 });
curve.addKnot(new double[] { 10.0, 15.0 });
curve.addKnot(new double[] { 20.0, 0.0 });
curve.addKnot(new double[] { 10.0, -10.0 });

for (double[] bezier : curve.getBeziers()) {
	System.out.println(Arrays.toString(bezier));
}

About

Library for global and incremental variants of John Hobby's curve drawing algorithm

Topics

Resources

Stars

Watchers

Forks

Languages