calculateAzimuthDifference

fun calculateAzimuthDifference(currentAzimuth: Double, targetAzimuth: Double): Double

Calculate the shortest angular difference between two bearings, normalized to ±180°.

Useful for UI display (e.g., "turn 15° right" vs "turn 345° left").

Examples:

  • current=350°, target=10° → +20° (turn right)

  • current=30°, target=350° → -40° (turn left)

  • current=180°, target=0° → ±180° (ambiguous, returns +180°)

Return

Angular difference in degrees (-180 to +180), positive = clockwise

Parameters

currentAzimuth

Current bearing in degrees (0-360)

targetAzimuth

Target bearing in degrees (0-360)