Created
June 28, 2013 22:40
-
-
Save jonobr1/5888725 to your computer and use it in GitHub Desktop.
Cubic bezier curve utility methods in JavaScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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