# Angle (in range 0 to 360 degrees) between two vectors in N-dimensional space

Suppose I have two vectors starting at the origin.

We can get the angle between the two vectors based on the dot product: $$\cos\theta=\frac{\langle v, w \rangle}{\|v\|\|w\|}$$ which still works if the number of dimensions is higher than 3 ( see How is the angle between 2 vectors in more than 3 dimensions defined? )

However, using this, I can get an angle only in the range(0, 180) degrees. Is there any way of possibly to get an angle in range of (0, 360) degrees, when the number of dimensions is higher than 3 ?

The only answer I found here is only about a 2 or 3 dimensional space: How to find an angle in range(0, 360) between 2 vectors?

• Subtract your result from 360 Commented Sep 22, 2017 at 16:22
• The angle between two vectors is always less than or equal to 180 degrees. Commented Sep 22, 2017 at 16:29
• The two vectors define a plane. You could pick $v$ to represent the '$x$' direction and use $w$ to define the '$y$' direction. Use Gram Schmidt to orthogonalise $w$ and then compute the angle of $w$ with respect to this basis. This is the hard way of doing what the last answer referenced above does, but it explains the geometric thinking behind it. Commented Sep 22, 2017 at 16:37

The angle between two vectors is always less than 180 degrees.

If we are talking about angles greater than 180 degrees we need some other vocabulary. We need an orientation. Which vector is "on the right."

One approach:

Construct a matrix with the two vectors you are comparing in the first two columns, and the rest of the columns as principal component vectors.

The sign of the determinant will tell you the orientation of the two vectors.

Update

In 3-D

Suppose your vectors are $(x_1,x_2,x_3), (y_1,y_2,y_3)$

Then the the sign of $\det \begin{bmatrix} x_1&y_1&0\\x_2&y_2&0\\x_3&y_3&1\end{bmatrix}$ will give you the orientation between your two vectors from the point of view of the positive z axis.

If you wanted to extend the dimension.

$\det \begin{bmatrix} x_1&y_1&0&0\\x_2&y_2&0&0\\x_3&y_3&1&0\\x_4&y_4&0&1\end{bmatrix}$