briantsim 108 Report post Posted June 7, 2007 Hi all, I has postion x1,y1 and x2,y2. How to calculate Degrees? 0 Share this post Link to post Share on other sites
PfhorSlayer 316 Report post Posted June 7, 2007 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?" 0 Share this post Link to post Share on other sites
Drilian 1067 Report post Posted June 7, 2007 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 ~\. 0 Share this post Link to post Share on other sites
Ezbez 1164 Report post Posted June 7, 2007 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. 0 Share this post Link to post Share on other sites
alvaro 21272 Report post Posted June 7, 2007 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. 0 Share this post Link to post Share on other sites
D_Tr 362 Report post Posted June 7, 2007 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. 0 Share this post Link to post Share on other sites
taby 1265 Report post Posted June 7, 2007 Quote:Original post by D_TrDrilian 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. 0 Share this post Link to post Share on other sites
grhodes_at_work 1385 Report post Posted June 7, 2007 So funny, these little songs! Thank you! 0 Share this post Link to post Share on other sites
D_Tr 362 Report post Posted June 7, 2007 @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. 0 Share this post Link to post Share on other sites