PDA

View Full Version : I need a trig expert; finding the angle from an anchored point and a moving one



Sirisian
July 5th, 2005, 03:05 PM
I wrote code to find an angle from an anchored point and a moving point a while ago, but don't know why it doesn't work anymore. I need someone to write the basic trig function to find an angle from two points. I don't want it in any code format just write it out. Thx in advance, this code will help me alot.

GW02
July 5th, 2005, 03:49 PM
Just:

1. Take the difference of the X coordinates. Let's call this xdiff.
2. Take the difference of the Y coordinates. Let's call this ydiff.
3. Take the inverse tangent of ydiff/xdiff.

That will give you the angle at the anchored point starting at the 3'oclock position if the point is on the right, and at the 9'oclock position of the point is on the left.

Hope that helps. (-:

Sirisian
July 5th, 2005, 05:23 PM
adjacent = mousex-unit.x;
opposite = unit.y-mousey;
angle=atan2(opposite,adjacent);
like this? Im pretty sure I need if statements to check for different events like if adjacent <0 and such, don't I?