CHAPTER 27
ECEF and 3D coordinate systems
Earth-Centered Earth-Fixed coordinates, converting lat/lon/altitude to XYZ, the ENU local frame, and 3D distances.
Most of the formulas in this guide project the Earth onto a flat surface. ECEF doesn't. It's a 3D Cartesian system with the origin at Earth's centre — the coordinate system GPS hardware and 3D rendering engines actually use.
Geodetic → ECEF coordinates
ECEF — Earth-Centered, Earth-Fixed
ECEF places the origin at Earth's centre of mass. The axes are fixed to the Earth and rotate with it:
- X-axis: points to the intersection of the equator and prime meridian (0°N, 0°E)
- Y-axis: points to 0°N, 90°E
- Z-axis: points to the North Pole
Units are metres. At Lahore (31.52°N, 74.36°E, ≈220 m):
Geodetic → ECEF
Given latitude , longitude , and altitude (metres above the ellipsoid):
where m, (WGS84).
const A = 6_378_137.0;
const E2 = 0.00669437999014;
function geodeticToECEF(latDeg, lonDeg, altM = 0) {
const lat = latDeg * Math.PI / 180;
const lon = lonDeg * Math.PI / 180;
const N = A / Math.sqrt(1 - E2 * Math.sin(lat) ** 2);
return {
x: (N + altM) * Math.cos(lat) * Math.cos(lon),
y: (N + altM) * Math.cos(lat) * Math.sin(lon),
z: (N * (1 - E2) + altM) * Math.sin(lat),
};
}
ECEF → Geodetic
The inverse has no closed form — use Bowring's iterative method or Zhu's formula:
function ecefToGeodetic(x, y, z) {
const p = Math.sqrt(x * x + y * y);
const lon = Math.atan2(y, x);
// Bowring iteration
let lat = Math.atan2(z, p * (1 - E2));
for (let i = 0; i < 5; i++) {
const N = A / Math.sqrt(1 - E2 * Math.sin(lat) ** 2);
lat = Math.atan2(z + E2 * N * Math.sin(lat), p);
}
const N = A / Math.sqrt(1 - E2 * Math.sin(lat) ** 2);
const alt = p / Math.cos(lat) - N;
return { lat: lat * 180 / Math.PI, lon: lon * 180 / Math.PI, alt };
}
ENU — the local frame
ENU stands for East-North-Up. It's a local Cartesian frame centred on a reference point. East (+X), North (+Y), and Up (+Z) are defined relative to that point on Earth's surface — making it intuitive for local navigation, drone control, and AR overlays. Unlike ECEF, ENU axes change as you move to a different reference point.
ECEF is a global system, but for local navigation you want a frame with East, North, Up axes anchored to a specific point. ENU gives you that.
Continue reading "ECEF and 3D coordinate systems"
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.
Related chapters
- Coordinate transforms — converting between CRS — ECEF as a transformation target
- Terrain and elevation data — elevation reads in ECEF or geodetic
- Coordinate systems: latitude and longitude — the geodetic input to ECEF
- Formula reference — Geodetic → ECEF and ECEF distance formulas