Created
July 5, 2012 16:25
-
-
Save garyb/3054646 to your computer and use it in GitHub Desktop.
JavaScript Bézier curve
This file contains 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
// `a` and `d` are anchor points, `b` and `c` are control points, and `t` is a scalar that specifies the point on the curve you want | |
var calcBezierValue = function (a, b, c, d, t) { | |
if (t < 0 || t > 1) return null; | |
return { x: (t * t * (d.x - a.x) + 3 * (1 - t) * (t * (c.x - a.x) + (1 - t) * (b.x - a.x))) * t + a.x, | |
y: (t * t * (d.y - a.y) + 3 * (1 - t) * (t * (c.y - a.y) + (1 - t) * (b.y - a.y))) * t + a.y }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment