Skip to content

Instantly share code, notes, and snippets.

@caughtinflux
Last active January 17, 2016 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caughtinflux/7910e647a2bdba673fb5 to your computer and use it in GitHub Desktop.
Save caughtinflux/7910e647a2bdba673fb5 to your computer and use it in GitHub Desktop.
Quadratic Bezier Control Point Calculation
// 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