# Calculating the angle between two vectors

1. Aug 6, 2010

### computerex

When calculating the angle between two vectors, I take the inverse cosine of the dot product of the two vectors normalized. This gives me the angle, however this does not specify whether the direction is backwards or forwards. In other words, it'll give me a range of -PI/2 to PI/2, then it loops back. Is there a way to figure out the angle in range of 0 to 360 degrees with this?

2. Aug 6, 2010

### Petr Mugver

Usually (for how it is normally defined, for example, in calculators) the cos^(-1) gives back values belonging to [0, pi], not [-pi/2 , pi/2] because in this interval the cos is not invertible.

Lets consider R^3.
If you want an angle between two normalized vectors u and v, belonging to [0, 2pi[, you have to define an orientation z for the plane where the two vectors are (the vector z lies in one side or the other of the plane, you choose).

(1) calculate alpha = cos^(-1) (u.v)
(2) calculate w = u x v
(3) if w.z > 0 or w.z = 0 then the answer is alpha
(4) if w.z < 0 then the answer is 2pi - alpha

3. Aug 6, 2010

### HallsofIvy

The "angle between two vectors" is, by definition, the smaller of the two angles formed by the intersection of lines in the direction of the two vectors. The angle between two vectors is always between 0 and $\pi$.

4. Aug 6, 2010

### Petr Mugver

Nevertheless, if you need it, you can define the angle in (0, 2pi), and to do so you have to decide an orientation.