MapMath

CHAPTER 08

Bearings, headings, and azimuths

Computing the angle from one point to another, normalizing to compass headings, and why bearings change along a path.

3 min read

When you know two geographic points, distance is one useful quantity — but direction is equally important. A bearing tells you which compass direction to face to look from one point toward another. It's the foundation of navigation, drone flight paths, sector queries ("show me restaurants to the north of me"), and directional UI elements like compass indicators.

optional — skip if familiarrefresher

Bearing, heading, and azimuth all mean the same thing in this context: the angle from north, measured clockwise, from 0° (north) to 360°. North = 0°, East = 90°, South = 180°, West = 270°. The term "bearing" is common in navigation; "azimuth" in astronomy and surveying; "heading" in aviation.

The bearing (or forward azimuth) is the angle, measured clockwise from north, from one point toward another. Use the calculator below to build intuition before the formula.

Bearing calculator

NNEESESSWWNW314.1° NW

From (A)

To (B)

Bearing A → B

314.05°

NW (314° from north)

Initial bearing formula

θ=arctan2(sinΔλcosφ2,    cosφ1sinφ2sinφ1cosφ2cosΔλ)\theta = \arctan2\Big(\sin\Delta\lambda \cdot \cos\varphi_2,\;\; \cos\varphi_1 \cdot \sin\varphi_2 - \sin\varphi_1 \cdot \cos\varphi_2 \cdot \cos\Delta\lambda\Big)

The result is in radians, in the range [π,π][-\pi, \pi]. Convert to degrees and normalize to [0,360)[0, 360):

bearing=(θ180π+360)mod360\text{bearing} = \left(\theta \cdot \tfrac{180}{\pi} + 360\right) \bmod 360

The +360 before mod 360 handles negative angles from arctan2 — it shifts the range from [-180, 180] to [0, 360) without changing positive values.

function bearing(lat1, lon1, lat2, lon2) {
  const toRad = d => d * Math.PI / 180;
  const φ1 = toRad(lat1), φ2 = toRad(lat2);
  const Δλ = toRad(lon2 - lon1);

  const y = Math.sin(Δλ) * Math.cos(φ2);
  const x = Math.cos(φ1) * Math.sin(φ2) -
            Math.sin(φ1) * Math.cos(φ2) * Math.cos(Δλ);

  return (Math.atan2(y, x) * 180 / Math.PI + 360) % 360;
}
Chapter 8 · Paid content

Continue reading "Bearings, headings, and azimuths"

You've reached the end of the free preview. Unlock all 22 paid chapters, including distance math, bearings, polygons, spatial indexing, and 3D map rendering — plus a downloadable PDF and the companion code repo.

  • All 22 paid chapters with worked examples
  • Downloadable PDF for offline reading
  • Companion GitHub repo (JavaScript + Python)
  • Free updates for life

Multiple payment options including Wise, PayPal, and bank transfer.