Skip to content

Instantly share code, notes, and snippets.

@jonobr1
Created June 28, 2013 22:40
Show Gist options
  • Save jonobr1/5888725 to your computer and use it in GitHub Desktop.
Save jonobr1/5888725 to your computer and use it in GitHub Desktop.
Cubic bezier curve utility methods in JavaScript.
function getPointOnCurve(v1, c1, c2, v2, t) {
return {
x: bezierPoint(t, v1.x, c1.x, c2.x, v2.x),
y: bezierPoint(t, v1.y, c1.y, c2.y, v2.y)
};
}
function bezierPoint(t, o1, c1, c2, e1) {
var C1 = (e1 - (3.0 * c2) + (3.0 * c1) - o1);
var C2 = ((3.0 * c2) - (6.0 * c1) + (3.0 * o1));
var C3 = ((3.0 * c1) - (3.0 * o1));
var C4 = (o1);
return ((C1*t*t*t) + (C2*t*t) + (C3*t) + C4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment