![]() |
|
Angle between two points? - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: Angle between two points? (/thread-2177.html) |
Angle between two points? - Graphic Ace - Nov 8, 2008 09:36 AM I am trying like crazy to get the angle of Rotation between two points an just can't seem to figure it out ![]() This is what I am trying to do Object Position (First Points) Object Position + Object Speed (Second Points) Distance between = Rotation? I have found a way to almost get the right angle but I need it to be FLAWLESS opp= Object.y - Object.y + Speed; adj = Object.x - Object.y + Speed; Rotation Angle = atan(opp/adj) *180/PI; Angle between two points? - Blacktiger - Nov 8, 2008 09:55 AM I'm confused, do you mean the angle between two points and the origin? You need three points for an angle. Angle between two points? - TomorrowPlusX - Nov 8, 2008 10:19 AM I'm not certain I understand the question fully, but that being said, look into atan2()... it's significantly more useful than vanilla atan() Angle between two points? - Graphic Ace - Nov 8, 2008 10:56 AM i just tried tan2 & it to failed. What I am trying to do is have Object point to Object + Speed Angle between two points? - ThemsAllTook - Nov 8, 2008 11:15 AM Please provide more details. What inputs do you have, and what output are you trying to compute? What does "i just tried tan2 & it to failed" mean? What does "Object point to Object + Speed" mean? Your question is incomprehensible the way it was phrased. Angle between two points? - Graphic Ace - Nov 8, 2008 11:39 AM If I launch a projectile what would the Angle be between the Objects present Position & the previous Position Angle between two points? - macnib - Nov 8, 2008 12:11 PM I still think your confused. But I think you might be assuming its the angle in respect to the ground? I suppose you could create a delta vector. //create delta delta_vec = position_new - position_old //copy it ground_ref = delta_vec ground_ref.y = 0 Now you have two vectors. Normalize both of them. Take the dot product of both vetors. Now, cos( theta ) = dot( v1 , v2 ) . Just do inverse arc cos on the dot product and you should get theta in radians. To convert to degrees just multiply it by 180/pie . It will return a value betwen 0 and 180. Hope that helps. |