2 Replies Latest reply on Oct 29, 2008 8:11 PM by James Newton, ACP

Measuring included angle between 3 points

I need a behavior that can measure the angle formed between two points and a sprite’s center. The first point is saved on mouseDown, the second point is the current mouse location. I’m using the law of cosines and if Director supported acos() I’d be done hours ago. I’ve got the formula re-written with atan(), unfortunately atan() presents two problems: 1. the function has singularities which I can deal with, 2. atan() returns an angle between 0<x<180, anyone know what I can test to determine if I need to add 180 to the angle to get a full 360 answer?
• 1. Measuring included angle between 3 points
Wow, I way over complicated this. Here’s a solution without using the law of cosines although it does use an undocumented atan2() function. I know the deltaAlpha variable is unnecessary in this example however in the real app this variable is broadcast to multiple sprites
• 2. Re: Measuring included angle between 3 points
The behavior I attach below does not compete with your 12-line handler in terms of concision. I felt it was worth adding to this thread because:
a) It provides a solution which does not block all other activity on the Stage
b) It shows how you can use 3D vector mathematics to solve a 2D rotation problem