Finding the angle from point1 to point2
Can someone please tell me how I find the angle from x1,y1 to x2,y2.
Thanks in advance,
Bluehair
The easiest way is to take the arctan of (y2 - y1)/(x2 - x1) since we know the tangent of the angle = the opposite side divided by the adjacent side.
tan-1((y2 - y1)/(x2 - x1))
That's in radians, so convert to degrees, if that's what you want.
(To convert from radians to degrees, just multiply your answer by 57.3 to get it in degrees)
Answer in degrees:
57.3*(tan-1((y2 - y1)/(x2 - x1))) = angle in degrees
Edited by - BeerNutts on July 3, 2001 12:42:10 PM
tan-1((y2 - y1)/(x2 - x1))
That's in radians, so convert to degrees, if that's what you want.
(To convert from radians to degrees, just multiply your answer by 57.3 to get it in degrees)
Answer in degrees:
57.3*(tan-1((y2 - y1)/(x2 - x1))) = angle in degrees
Edited by - BeerNutts on July 3, 2001 12:42:10 PM
My Gamedev Journal: 2D Game Making, the Easy Way
---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
Just as an aside, there''s also the question of the angle between (x1,y1) and (x2,y2), the third point (which forms the "center" of the angle) being the Origin. This is quickly calculated at the inverse cosine of the dot product of the two point vectors devided by the product of the vector magnitudes.
ie ang = cos-1((x1*x2 + y1*y2)/((x12 + y12)1/2 * (x22 + y22)1/2))
Just for kicks.
ie ang = cos-1((x1*x2 + y1*y2)/((x12 + y12)1/2 * (x22 + y22)1/2))
Just for kicks.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement