Skip to content

Instantly share code, notes, and snippets.

@zouloux
Last active August 29, 2015 14:19
Show Gist options
  • Save zouloux/c02777e5fdbb002cbce3 to your computer and use it in GitHub Desktop.
Save zouloux/c02777e5fdbb002cbce3 to your computer and use it in GitHub Desktop.
Compute angle between 3 points
protected static function angleBetweenPoints (p0:Point, p1:Point, p2:Point):Number
{
var a:Number = Math.pow(p1.x - p0.x, 2) + Math.pow(p1.y - p0.y, 2);
var b:Number = Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2);
var c:Number = Math.pow(p2.x - p0.x, 2) + Math.pow(p2.y - p0.y, 2);
return Math.acos((a + b - c) / Math.sqrt(4 * a * b));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment