Angle between two points?

Member
Posts: 23
Joined: 2007.12
Post: #1
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;
Member
Posts: 254
Joined: 2005.10
Post: #2
I'm confused, do you mean the angle between two points and the origin? You need three points for an angle.
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
I'm not certain I understand the question fully, but that being said, look into atan2()... it's significantly more useful than vanilla atan()
Member
Posts: 23
Joined: 2007.12
Post: #4
i just tried tan2 & it to failed.

What I am trying to do is have

Object point to Object + Speed
Moderator
Posts: 1,559
Joined: 2003.10
Post: #5
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.
Member
Posts: 23
Joined: 2007.12
Post: #6
If I launch a projectile what would the Angle be between the Objects present Position & the previous Position
Member
Posts: 81
Joined: 2007.05
Post: #7
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.