Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Compass Headings
Message
General information
Forum:
Games
Category:
Trivia
Miscellaneous
Thread ID:
01643702
Message ID:
01643731
Views:
35
>>>General sort of question:
>>>
>>>I'm drawing a compass and need to determine the 'shortest' direction in which to rotate the compass (clockwise or anti-clockwise) between old and new bearings (in degrees).
>>>In most cases it is simple but when the old and new values span the 0 degree point those solutions don't work.....
>>>
>>>Anyone got a foolproof algorithm (language doesn't matter - just the logic)
*

You may have gotten a solution already, though I had to try one more time:
I think it should be a function of the angle between the two bearings, and that you'd always want to move the needle in the the direction determined by the smaller angle. Which means that you need only a modifier for cases where the diff angle is a reflex angle.
If that is correct, then:
SIGN((a1 - a0) * SIN(ABS(a1 - a0)))
where a0 is the current bearing, and a1 is the new bearing, and the return values of
1 - clockwise
-1 anti-clockwise
0 either
should to work as expected with the examples that you gave before.
For vfp, it should be
SIGN((a1 - a0) * SIN(ABS(DTOR(a1 - a0))))
Previous
Reply
Map
View

Click here to load this message in the networking platform