Calculating azimuths from planimetric coordinates is complicated when the available implementations of inverse trigonometric functions have ranges spanning only 180° instead of 360° as azimuth requires. A tangent half-angle formula is used to derive a formula with only one special case (due South) that computes azimuth for the whole circle.
Meyer, Thomas H. and Conshick, Jacob, "A Simple Formula to Calculate Azimuth without a Two-Argument Arctangent Function" (2014). Department of Natural Resources and the Environment Articles. 15.