Mathematical Overflow in Geographical Calculations

It may sound like a marginal problem, but it can be found in a multitude of software – in apps and on websites as well. Prominent example: The site iss.de.astroviewer.net shows the actual position of the ISS (International Space Station). The position is shown on a world map and is updated every second, moving roughly in an eastward direction (+/- 51.6°). But guess what happens, when the ISS is crossing the meridian at 180° longitude. It jumps back around the globe to the west in big steps until it matches the current position again. This strange behaviour takes approx. 1 minute, and then the normal movement continues.

The reason for this bug is obviously a mathematical algorithm, which handles the 180° transition incorrectly. (Btw: a similar bug can sometimes be observed at the 360° transition.) In the example above, it is only a strange effect, which could be ignored with a grin. But imagine an autopilot controlling an aircraft or ship. Assume it has to perform a slight course change to portside, say from 5° to 355°. Due to a software bug, the vessel performs an (almost) full circle of 350° to starboard instead. This could lead to severe problems, even a crash, if there is an obstacle.

almost full circle

The mathematical solution for correct behaviour is the following: Always use angular differences, normalised to a range of +/- 180°. These deltas can be used for further calculations, e.g. filtering. Then the final result has to be adjusted again, this time to the range of 0°...360°. Sounds complicated, but in fact it’s quite simple. And it provides correct results.