Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
    
I've edited this as I understand it. If I interpreted your question incorrectly, please change it or let me know. –  mixedmath Feb 16 '12 at 18:10
    
That's correct, thanks. As you might guess, English isn't my mother tongue. :D –  Ruuhkis Feb 16 '12 at 18:33

2 Answers 2

up vote 3 down vote accepted

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

share|improve this answer
    
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! –  Ruuhkis Feb 17 '12 at 7:28

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.