Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have two two-dimensional unit vectors a and b. I'm trying to get their angle related to their order. arc cosine of the dot product returns the absolute value of the angle. if b is before a I want to get negative angle.
e.g. if a is on 1 o'clock and b is on 2 o'clock I want to get answer of 30 degrees but if a is on 2 o'clock and b is on 1 o'clock I want to get answer of -30 degrees. answers should be in radians, I used degrees for simpler explanation.
How can I do this? a method for finding who is before who will be good enough. this is for an application, so an answer of "just look at them" won't work, but a mathematical relation will be good (e.g. some equation that is negative only if b is before a).

share|improve this question
2  
You might be interested in Determinants (en.wikipedia.org/wiki/Determinant): the determinant of two 2d vectors is the product of the norms and the sine between the two vectors; the sine can give you the sign. –  Najib Idrissi Jun 13 '11 at 12:23
1  
If this is for a computer program, then your programming language might have a function called atan2(x,y). Check for its documentation to make sure, but IIRC that returns the angle (with sign!) between the vectors $xi+yj$ and the positive $x$-axis. If $a=(x_1,y_1)$ and $b=(x_2,y_2)$ then you get your result by carefully comparing the outputs of atan2($x_1,y_1$) and atan2($x_2,y_2$). Emphasis on CAREFUL. The angles wrap around the circle, so you need to make up your mind, on how you treat the case, when one angle is -175 degrees and the other 175. Add multiples of $2\pi$ when appropriate! –  Jyrki Lahtonen Jun 13 '11 at 12:26
add comment

1 Answer

up vote 4 down vote accepted

Treat them as 3D vectors with $z=0$ and find the cross product.

share|improve this answer
    
Isn't there an easier way? –  Dani Jun 13 '11 at 12:22
    
@Dani, it boils down to two multiplications and a comparison. You're not going to get much easier than that. –  Peter Taylor Jun 13 '11 at 12:25
    
yes, I've been able it to that. didn't know cross product is such an easy operation. –  Dani Jun 13 '11 at 12:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.