angle $0$ to $2\pi$ between two 3Dvectors Ok this is for a computer game I'm learning to program with. How do you find angle between two normalized 3D vectors so that you get the resulting angle in the range $[0,2\pi]$ or $[-\pi,\pi]$?
Using a simple Anti-cosine only gives values in the range $[0,\pi]$.
 A: Two dimensions
The angle $\theta$ between two unit vectors $a,b$ in two dimensions can be defined so that it lies in $[0,2\pi]$ or in $[-\pi,\pi]$, as follows:

*

*Let $\theta$ be the least amount by which one has to turn $a$ counterclockwise so it becomes $b$. Then $\theta$ is in $[0,2\pi)$.


*Let $\theta$ be the least amount by which one has to turn $a$ so it becomes $b$, choosing either counterclockwise (positive) or clockwise (negative) direction. Then $\theta$ is in $(-\pi,\pi]$ or in $[-\pi,\pi)$ depending on how you handle the edge case of $a,b$ being opposite to each other.
Three dimensions
Given two unit vectors $a,b$ in three dimensions, we don't have either of the options 1 or 2, because there isn't a well-defined concept of "clockwise". If you imagine a plane spanned by $a,b$ and try to follow the 2D approach, the  result depends on what side of the plane you look at. So, the only reasonable way to define the angle in 3D is

*

*Let $\theta$ be the least amount by which one has to turn $a$  so it becomes $b$.

Then $\theta$ is in $[0,\pi]$ and is given by the formula $\theta=\cos^{-1}(a\cdot b)$.
