1
$\begingroup$

Suppose I am moving in a certain compass bearing (e.g. $270^\circ$) and I want to be going in a different direction (e.g. $120^\circ$). Is there a formula or series of math operations that I can use to determine which direction I should turn (I want the shorter direction)?

I've tried to increase my angle, i.e. turn counterclockwise, if $\text{target bearing} - \text{current bearing} < 360 - (\text{target bearing} - \text{current bearing})$, and it only seems to work in some cases.

Please help! I've been having lots of trouble.

  • 0
    That's correct, thanks. As you might guess, English isn't my mother tongue. :D2012-02-16

3 Answers 3

6

Let $T$ be the target bearing and $C$ be the current bearing. Let's consider three numbers:

$\begin{align}\alpha&=T-C\\ \beta&=T-C+360°\\ \gamma&=T-C-360°\end{align}$

Now, whichever of $|\alpha|$, $|\beta|$, and $|\gamma|$ is the smallest tells us which of $\alpha$, $\beta$, and $\gamma$ is relevant and if the one with the smallest absolute value is positive, go clockwise, and if it's negative, go counterclockwise.

edit The animation below shows the locations of the target point in red and the current point in blue, for various values of each, with the values of $|\alpha|$, $|\beta|$, and $|\gamma|$ as well as the motion (which is indicated by an arc along the circle) shown in the lower right corner.

enter image description here

  • 0
    This is absolutely best answer one can ever get! Thanks for amazing visualizing too, I am more of visual learner. :) Couldn't thank you enough!2012-02-17
4

If you're looking for a "one-liner", let $T$ be the target bearing and $C$ be the current bearing:

$\begin{align}\delta&=(T-C+540°)\bmod360°-180°\end{align}$

The shortest rotation distance in degrees is given by $\delta$. Positive values indicate clockwise rotation, negative values indicate counterclockwise rotation.

$180°$ turns are always expressed as counterclockwise $-180°$.

  • 0
    Awesome, thanks!2018-08-30
0

Say you're going at bearing $a$ and your target bearing is $b$. I'll assume that both $a$ and $b$ are between zero (inclusive) and 360 (exclusive), and I'll also assume that the direction of increasing bearing is counterclockwise (that's the usual convention in higher math, and I think it's the one you are using). Here are the cases:

If $a\lt b$, and $b-a\le180$, turn counterclockwise.

If $a\lt b$, and $b-a\gt180$, turn clockwise.

If $a\gt b$, and $a-b\le180$, turn clockwise.

If $a\gt b$, and $a-b\gt180$, turn counterclockwise.