Jump to content
  • Advertisement
Sign in to follow this  
briantsim

Degrees Question?

This topic is 4124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
I like to use a little song:

~\. The dot product of the two position vectors is equal to the cosine of the angle between them ~\.

Sing it to the tune of "Do your ears hang low?"

Share this post


Link to post
Share on other sites
The second verse goes something like

~\. Consequently the angle is the arc cosine of the dot product of the two position vectors ~\.

Finally, the refrain is:

~\. Divide by pi and multiply by one hundred and eighty for degrees ~\.

Share this post


Link to post
Share on other sites
Bravo! Encore!

And an alternative method:

atan( (y2 - y1) / (x2 - x1) )

since tangent is the opposite over adjacent, you take the arc tangent of the opposite over adjacent to get the angle.

Though you have to check whether or not x2 - x1 is equal to zero before doing the division. Some languages (like C++) supply an "atan2" function which make this simpler:

atan2( y2 - y1, x2 - x1 )

No need to check for dividing by zero. It basically takes two parameters, the opposite and the adjacent side's lengths.

Share this post


Link to post
Share on other sites
Those two methods compute different things. Of course, the OP didn't specify which of the two he wanted, so it's not like one of them is correct and one is incorrect. Because he said "positions", he probably meant to get the atan answer. Anyway, two positions don't determine an angle, so the question needs to be posed better.

The acos version measures the angle (x1,y1)-(0,0)-(x2,y2), without sign. The atan version measures the angle (x1+1,y1)-(x1,y1)-(x2,y2), with sign.

Also, in the acos version, you need to divide the dot product by the sizes of the two vectors.

Share this post


Link to post
Share on other sites
Drilian and PfhorSlayer i think you 're talking about normalized vectors. For vectors of arbitary length, like position vectors, take the dot product of the two vectors, then divide the dot product by both the lengths of the two vectors, and then you have the cosine of the angle between the vectors.

Share this post


Link to post
Share on other sites
Quote:
Original post by D_Tr
Drilian and PfhorSlayer i think you 're talking about normalized vectors. For vectors of arbitary length, like position vectors, take the dot product of the two vectors, then divide the dot product by both the lengths of the two vectors, and then you have the cosine of the angle between the vectors.


Multiplication is commutative in real algebra.

Share this post


Link to post
Share on other sites
@taby:

Sorry mate i didn't understand your comment. All i wanted to say is that the dot product of 2 vectors is not just the cosine of the angle between them, but it is the cosine multiplied by their lenghts, namely multplied by |v1|*|v2|. I don't think i murdered commutativeness of multiplication anywhere in my post :P. This is what alvaro is also saying in his last comment too.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!