Fast way to compare angles w/o their measures

71 Views Asked by At

I need an efficient way to compare the measures of two angles in $\mathbb{R^2}$ that ideally relies on the smallest number of arithmetic operations and no trigonometric operations (no $\arccos$) or square roots. Given two angles $\angle{p_1p_0p_2}$ and $\angle{p_3p_0p_4}$ whose measures are in the range $\big(0,{\pi}\big)$ radians with vertex $p_0$ at the origin, what is the fastest way to compare the measures of the angles (i.e. find which angle has the largest measure/which one has the smallest measure)?

I understand that the $z$ component of the cross product of two or more pairs of vectors can be used to compare angles where $\theta \in \big(0,\frac{\pi}{2}\big)$ radians. As stated above, however, I need to compare angles with $\theta \in \big(0,{\pi}\big)$.

Any ideas?

2

There are 2 best solutions below

1
On BEST ANSWER

Let $\theta$ be the angle between $p_1$ and $p_2$, and $\phi$ the one between $p_3$ and $p_4$. Since $p_1 \cdot p_2 = |p_1| |p_2| \cos \theta$, the sign (positive or negative) of $p_1 \cdot p_2$ tells you whether $\theta \in [0, \pi/2)$ or $(\pi/2, \pi)$. Similarly for $\phi$, and so you may already be able to tell which is larger.

If both dot products have the same sign, then define $$ r_\theta := (p_1 \cdot p_2)^2 |p_3|^2 |p_4|^2 = |p_1|^2 |p_2|^2 |p_3|^2 |p_4|^2 \cos^2 \theta$$ and $$ r_\phi := (p_3 \cdot p_4)^2 |p_1|^2 |p_2|^2 = |p_1|^2 |p_2|^2 |p_3|^2 |p_4|^2 \cos^2 \phi$$ and so comparing $r_\theta$ and $r_\phi$ tells you which has the largest cosine squared, from which you can figure out what is the larger angle. At worst, this takes 6 dot products, 4 multiplications, and 4 comparisons.

2
On

Try the dot product. You will like the results.

Because, dot product of two vectors will be equal to the cosine of the angle between the vectors, times the lengths of each of the vectors.

You do the rest.