MapMath

CHAPTER 09

Destination points — moving on a sphere

Given a starting point, bearing, and distance, compute the destination on a sphere — used for geofences, range rings, and dead reckoning.

2 min read

The inverse of distance/bearing: given a starting point, a bearing, and a distance, find the destination on the sphere. This operation is called dead reckoning in navigation — it's how ships historically computed position before GPS. In modern apps it's used for geofence construction, range rings, path simulation, and anywhere you need to place a point at a known offset from another.

Try it live before diving into the derivation.

Destination point calculator

A (31.5, 74.4)B (34.64, 78.22)45° / 500 km
dest lat: 34.64185
dest lon: 78.22367

The formula

optional — skip if familiarrefresher

Angular distance δ=d/R\delta = d / R converts a linear distance (metres) into the angle it subtends at Earth's centre. A 1 km arc on a sphere of radius 6,371 km subtends 1000/6,371,008.80.0001571000 / 6{,}371{,}008.8 \approx 0.000157 radians. Working in angular distance keeps the sphere math dimensionally consistent — all the trig functions expect angles, not metres.

Let δ=d/R\delta = d / R be the angular distance in radians. This normalises the linear distance by Earth's radius to get the central angle subtended by the arc.

φ2=arcsin ⁣(sinφ1cosδ+cosφ1sinδcosθ)\varphi_2 = \arcsin\!\big(\sin\varphi_1 \cos\delta + \cos\varphi_1 \sin\delta \cos\theta\big) λ2=λ1+arctan2 ⁣(sinθsinδcosφ1,  cosδsinφ1sinφ2)\lambda_2 = \lambda_1 + \arctan2\!\big(\sin\theta \sin\delta \cos\varphi_1,\; \cos\delta - \sin\varphi_1 \sin\varphi_2\big)

The first equation derives the new latitude by rotating the starting point through angle δ in the direction θ. The second computes the longitude offset using arctan2 to handle the full 360° range correctly.

function destination(lat1, lon1, bearingDeg, distanceMeters) {
  const R = 6371008.8;
  const δ = distanceMeters / R;
  const θ = bearingDeg * Math.PI / 180;
  const φ1 = lat1 * Math.PI / 180;
  const λ1 = lon1 * Math.PI / 180;

  const φ2 = Math.asin(
    Math.sin(φ1) * Math.cos(δ) +
    Math.cos(φ1) * Math.sin(δ) * Math.cos(θ)
  );
  const λ2 = λ1 + Math.atan2(
    Math.sin(θ) * Math.sin(δ) * Math.cos(φ1),
    Math.cos(δ) - Math.sin(φ1) * Math.sin(φ2)
  );

  return {
    lat: φ2 * 180 / Math.PI,
    lon: ((λ2 * 180 / Math.PI) + 540) % 360 - 180   // normalize to [-180, 180]
  };
}
Chapter 9 · Paid content

Continue reading "Destination points — moving on a sphere"

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.