Degrees Question?

Started by
7 comments, last by asdfg__12 16 years, 10 months ago
Hi all, I has postion x1,y1 and x2,y2. How to calculate Degrees?
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?"
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 ~\.
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.
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.

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.
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.
So funny, these little songs! Thank you!
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
@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.

This topic is closed to new replies.

Advertisement