Hand Calculations logo Hand Calculations All help pages ▾

Magnetic Heading⚠ unverified

Aerospace / Navigation · Compute the magnetic heading with declination correction

Parameters

InputSymbolUnitDefaultDescription
mag_xmagxT1.0Magnetometer reading along the x-axis, in teslas (T) or any consistent unit
mag_ymagyT1.0Magnetometer reading along the y-axis, in teslas (T) or any consistent unit
declinationdeclination0.0Magnetic declination correction, in degrees. Default is 0.0
OutputSymbolUnitDescription
resultheadingHeading, in degrees, normalised to [0, 360)

The science & history

Understanding the Parameters

Derivation (Approaching a Proof)

Model the local Earth field, in the aircraft's horizontal body frame, as a horizontal vector of magnitude $B_h$ pointing toward magnetic north. If the aircraft's nose (body x-axis) is rotated by heading $\psi_m$ (measured clockwise from magnetic north) relative to that field, the field's components sensed along the body axes are:

$$B_x = B_h\cos\psi_m, \qquad B_y = -B_h\sin\psi_m$$

(the exact signs depend on the axis convention; the implementation uses $\operatorname{atan2}(B_y,B_x)$ directly). The heading is recovered by taking the four-quadrant arctangent of the two components, which cancels the unknown magnitude $B_h$:

$$\psi_m = \operatorname{atan2}(B_y, B_x).$$

Using $\operatorname{atan2}$ (not $\arctan$) is essential so the heading is correct in all four quadrants and well-defined when a component is zero — a compass must read all $360^\circ$.

Finally, convert magnetic heading to true by adding the local declination and normalising:

$$\psi = \big(\operatorname{atan2}(B_y, B_x) + \delta + 360^\circ\big) \bmod 360^\circ. \qquad\blacksquare$$

The $\bmod 360^\circ$ (with the $+360^\circ$ to avoid negative results) wraps the answer into the standard $[0^\circ,360^\circ)$ compass range.

Dimensional check. $B_x, B_y$ share units (tesla), so their ratio inside $\operatorname{atan2}$ is dimensionless and the result is an angle; adding the declination angle $\delta$ keeps it an angle ✓ — the field magnitude cancels, which is why "any consistent unit" works for $B_x,B_y$.

History and Development

Related Concepts: Initial Heading, Great-Circle Distance, Cross Track Error, Gps Dilution Of Precision, Time To Go

Notes: $\operatorname{atan2}(B_y,B_x)$ gives the magnetic heading; adding declination $\delta$ makes it true (so the output, despite the name, is true heading). Declination and output are degrees (both mislabelled dimensionless); east declination positive. 2-axis / level only — no tilt compensation, so bank/pitch corrupt it (real AHRS use 3 axes + gyros/accelerometers). Corrects declination, not aircraft deviation (compass swing handles that). Field magnitude cancels. Defaults ⇒ $45^\circ$.

← Back to the workspace  ·  All help pages  ·  Getting started