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

1.6k Views Asked by At

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?

2

There are 2 best solutions below

3
On BEST ANSWER

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.

2
On

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).