Lat/Lng to ECEF Converter

Convert WGS-84 lat/long/altitude to ECEF Cartesian XYZ

Ad placeholder (leaderboard)

WGS-84 geodetic to ECEF

This converter turns a geographic position — latitude, longitude and ellipsoidal height — into Earth-Centered Earth-Fixed (ECEF) Cartesian coordinates. ECEF is the frame used internally by GPS receivers, satellite tracking, and many geodetic computations because it expresses a point as plain X, Y, Z metres relative to the centre of the Earth.

How it works

The transform is closed-form. First compute the prime-vertical radius of curvature N at the given latitude:

N = a / sqrt(1 - e^2 * sin^2(lat))

where a = 6378137 m (WGS-84 semi-major axis) and e^2 = f(2 - f) is the first eccentricity squared from the flattening f = 1/298.257223563. Then:

X = (N + h) * cos(lat) * cos(lon)
Y = (N + h) * cos(lat) * sin(lon)
Z = (N * (1 - e^2) + h) * sin(lat)

with latitude and longitude in radians and h the ellipsoidal height in metres. The (1 - e^2) factor on Z accounts for the Earth being an oblate spheroid rather than a sphere.

Example and notes

The Eiffel Tower at roughly 48.8584° N, 2.2945° E, 330 m gives X ≈ 4 200 952 m, Y ≈ 168 386 m, Z ≈ 4 780 740 m. Remember the height must be above the ellipsoid, not above sea level — in Paris the geoid sits about 44 m above the ellipsoid, so an MSL height needs that undulation added before conversion. The transform is exact in the forward direction; converting back to latitude and longitude requires an iterative or Bowring-style solution.

Ad placeholder (rectangle)