Exercise 1: Naive vs. Correct Heading Difference for a Drone — Possible Solution ==================================================================== THE NAIVE CALCULATION ------------------------------ current = 5 degrees, target = 340 degrees. naive turn = target - current = 340 - 5 = 335 degrees. Taken literally, this tells the drone to turn 335 degrees - almost a full rotation - to reach its target heading. THE CORRECT, WRAPPED CALCULATION ------------------------------ Using this chapter's own wrapped-difference formula, (target - current + 180) mod 360 - 180: (340 - 5 + 180) mod 360 - 180 = 515 mod 360 - 180 = 155 - 180 = -25 degrees WHICH DIRECTION THE DRONE SHOULD ACTUALLY TURN ------------------------------ A heading of 5 degrees and a heading of 340 degrees are actually close neighbors on the compass, straddling due north (0 degrees) - 340 is only 20 degrees short of 360/0, and 5 is only 5 degrees past it, so the true angular gap between them is just 25 degrees. The correct result, -25 degrees, means the drone should turn 25 degrees in the negative (counterclockwise, i.e. turning left/toward smaller heading values) direction - a small, quick adjustment - rather than the naive result's 335-degree turn, which would send the drone almost all the way around in the wrong (clockwise) direction to arrive at the same final heading. WHY THE TWO RESULTS DESCRIBE THE SAME FINAL ORIENTATION BUT VERY DIFFERENT PATHS ------------------------------ Both a 335-degree clockwise turn and a 25-degree counterclockwise turn end up facing the same final direction, since compass headings wrap around every 360 degrees. But a real drone executing "turn 335 degrees" would take far longer, use far more energy, and behave in a way no reasonable observer would expect, compared to the much shorter and more natural 25-degree correction - exactly the practical consequence of this chapter's own naive-subtraction bug. WHY THIS WORKS AS AN ANSWER ------------------------------ The answer computes both the naive and the corrected values explicitly using this chapter's own formula, and explains the real practical consequence of choosing the wrong one - not just that the numbers differ, but that one produces a sensible small correction and the other an absurd near-full-rotation for the identical final orientation.