# Is it possible to get the angle between two vectors in a single direction?

I'd like to compute the angle between two vectors but always in a anticlockwise manner. Is this possible?

I know the formula is arc cos (dot product of vectors / product of magnitudes of vectors) but this is not what I need because if I have a vertical vector point up for example. I can have a vector pointing left or right and the formula would give me 90 degrees. I want it to give me 90 degrees for the right vector and 270 for the left one. Is this possible?

• I suppose you want to do this in two dimensions? Then you can use polar coordinates to do it Apr 10 '14 at 8:08
• Oh no it is in 3d. Im sorry I forgot to mention that
– Ogen
Apr 10 '14 at 8:08

You can do it in 2D but not in 3D.

This is because in 2D, it is clear which vector is anticlockwise to the other.

However, in 3D space, what is 'anticlockwise'? Looking at the two vectors from one perspective may say A is anticlockwise from B, but looking at it from another perspective may say that B is anticlockwise from A.

When it comes to 3D space, the concept of 'left and right' becomes a bit more ambiguous due to the added degree of freedom (in terms of shifting your perspective).

• But it is not impossible: any two vectors span a plane on which you can set polar coordinates. The orientation of this plane contains some ambiguity, but you can make a consistent choice by demanding the normal vector to this plane to have positive z-coordinate. Apr 10 '14 at 8:15
• I don't need it to be anti clockwise or clockwise, I just need it to be in a consistent direction all the time. And that direction I chose is anticlockwise
– Ogen
Apr 10 '14 at 8:19

From the two vectors, define the plane spanned by these two vectors. Choose the orientation to be such that the normal vector to this plane has positive $z$-coordinate. Then set polar coordinates on this plane using this orientation and compute the phases of both these vectors. The difference of the phases mod $2 pi$ then yields your required result.

In practice, this is not too difficult: calculate the angle $\phi$ using the known formulae for the inner-product. Then calculate the cross-product, which yields the normal vector to one of the orientations. If the $z$ coordinate of this result is positive, use $\phi$. If it is negative, use $360-\phi$. If $z=0$, the choice is yours to make, say that you then use $\phi$.

To avoid ambiguity in the case $z=0$, you should really look at a different coordinate. For example, if the $x$-coordinate is positive, take $\phi$, otherwhise $360-\phi$. Then if $x$ is also zero, to the same with $y$. They can't all be zero for two different non-zero vectors. If you don't do this, then for two vectors, one on the $z$ axis, one in the $x-y$-plane, you still don't have a consistent angle.

• What if the z coordinate of the cross product is 0?
– Ogen
Apr 10 '14 at 8:31
• see the last line of the answer;) Apr 10 '14 at 8:32
• Woops, I feel stupid
– Ogen
Apr 10 '14 at 8:33