Given 2 vectors, what's the least computationally intensive way to determine if one is more than 90 degrees away from the other?

81 Views Asked by At

I would like to determine the angle between two arbitrary vectors. Using the cross product, I can do:

$\theta_1 = sin^{-1}\Big({{\lvert a \times b \rvert} \over {\lvert a \rvert \lvert b \rvert}}\Big)$

and use the cross product to get the rotation axis.

However, this will give me a range between $[-90, 90]$ degrees, but for anything greater than that, it will place the cross product vector in the opposite direction and give me a range between $[-90, 90]$ degrees.

So, in the meantime, I have to do a test for direction by taking the 2nd vector, multiply it by the rotation matrix resulting from of $-\theta_1$ and ${\lvert a \times b \rvert}$ and by using the dot product, get the angle:

$\theta_2 = cos^{-1}\Big({{\lvert a \cdot b \rvert} \over {\lvert a \rvert \lvert b \rvert}}\Big)$

If that angle is not $0$, then subtract $180$ from the $\theta_1$ as the result.

So my question is: Is there a less computationally intensive way to do this?

1

There are 1 best solutions below

2
On BEST ANSWER

The angle $\theta$ between $\bf a$ and $\bf b$ is greater than $90^{\circ}$ iff the dot product $${\bf a} \cdot {\bf b} := a_1 b_1 + \cdots + a_n b_n$$ of $\bf a$ and $\bf b$ is negative, as this quantity coincides with $$|{\bf a}| |{\bf b}| \cos \theta .$$ This entails $n$ multiplications and $n - 1$ additions, and so is relatively computationally cheap.