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
).
dot product negative angle
3
$\begingroup$
trigonometry
-
1If 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! – 2011-06-13
1 Answers
4
Treat them as 3D vectors with $z=0$ and find the cross product.
-
0yes, I've been able it to that. didn't know cross product is such an easy operation. – 2011-06-13