Skip to content

Instantly share code, notes, and snippets.

@choppingblock
Created September 14, 2013 02:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choppingblock/6558389 to your computer and use it in GitHub Desktop.
Save choppingblock/6558389 to your computer and use it in GitHub Desktop.
Have a quadratic bezier curve, need to figure out an angle along the way. This should work quite well, easy to convert to JavaScript.
public static function quadraticBezierAngle(value:Number, anchor1:Point, anchor2:Point, control:Point):Number {
var uc:Number = 1 - value;
var dx:Number = (uc * control.x + value * anchor2.x) - (uc * anchor1.x + value * control.x);
var dy:Number = (uc * control.y + value * anchor2.y) - (uc * anchor1.y + value * control.y);
return Math.atan2(dy, dx);
}
@symil
Copy link

symil commented Oct 31, 2017

If anyone wants the JavaScript version:

function quadraticBezierAngle(t, anchor1, anchor2, control) {
  let u = (1 - t);
  let dx = (u * control.x + t * anchor2.x) - (u * anchor1.x + t * control.x);
  let dy = (u * control.y + t * anchor2.y) - (u * anchor1.y + t * control.y);

  return Math.atan2(dy, dx);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment