Skip to main content
GameDev.net gamedev.net
🔒 Locked

angle from 2 points

Started by redmonkey Apr 16, 2001 at 8:59 AM 4 replies 500+ views
Original Post
redmonkey
redmonkey
i had this a while ago, but lost it again how do i work out the angle from 2 points?(x/y) i cant remeber if its arccos() or invcos() or tan() or somehting, please help! i know theres a sqrt in there somewhere too (any language im flexible __________________ graham "red" reeves. red@deadpenguin.org www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
acraig
acraig
Ok. Try a diagram



. (x2,y2)
/ |
/ |A
/a |
. ----
(x1,y1) B



Now I assume that you have your two points and you want the angle ''a'' with respect to the horizontal. We can see that we can use tan a = (A/B).

Now:
A = ( y2 - y1 )
B = ( x2 - x1 )

So:
angle = tan^-1 ( (y2-y1)/(x2-x1) )






-------
Andrew
LilBudyWizer
LilBudyWizer
Use atan2(x2-x1,y2-y1).
Keys to success: Ability, ambition and opportunity.
Beer Hunter
Beer Hunter
Well, it is possible to do it with arccos, but that requires extra effort, and seeing that arccos is dependant on arctan anyway, it''s not worth it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.