Last active
January 17, 2016 17:13
-
-
Save caughtinflux/7910e647a2bdba673fb5 to your computer and use it in GitHub Desktop.
Quadratic Bezier Control Point Calculation
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
// http://en.wikipedia.org/wiki/Bézier_curve#Quadratic_B.C3.A9zier_curves | |
// `t` is the percentage of curve where `third` resides, and should be in [0, 1] | |
CGPoint GetControlPointForQuadBezier(CGPoint start, CGPoint end, CGPoint third, CGFloat t) { | |
CGPoint ctrl = CGPointZero; | |
CGFloat t2 = pow(t, 2); | |
ctrl.x = -(((pow((1 - t), 2) * start.x) + (t2 * end.x) - third.x) / (2 * t * (1 - t))); | |
ctrl.y = -(((pow((1 - t), 2) * start.y) + (t2 * end.y) - third.y) / (2 * t * (1 - t))); | |
return ctrl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment