Distance through the Earth

This calculator calculates the distance from one point on the Earth to another point, going through the Earth, instead of going across the surface.

If you want to measure distance from one point on the Earth to another point, you should use the great-circle or orthodromic distance formula. We even have two calculators for this: the one which uses haversine formula, and the another one which uses Vincenty formula.

However, what if you want to know the distance between two points on the Earth through the Earth, not across the surface? As it turns out, the problem is relatively simple, except for couple of gotchas. The calculator below finds the distance between two points through the Earth, and the derivation of formula with all gotchas can be found below the calculator.


Distance through the Earth





Digits after the decimal point: 3
Distance, km
Save the calculation to reuse next time or share with friends.

Distance through the Earth

Ok, we have two points on the Earth surface, defined by their latitude and longitude, and we want to know the distance between them going "through" the Earth, instead of around it. Technically, we have spherical coordinates of each point in three-dimensional space, because we know radius of the Earth, inclination angle (latitude) and azimuth angle (longitude). If we convert these to cartesian coordinates, with x, y, z in three-dimensional space, we can easily find the distance using well-known Euclidean distance formula:
D=\sqrt{(x_2 - x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2}

So, let's define our Cartesian coordinate system. Origin will be the center of the Earth, x-axis will point to zero meridian intersection with the equator plane, y-axis will point to 90 degrees west meridian intersection with equator plane, and z-axis will point to the North.

Cartesian coordinate system
Cartesian coordinate system

\phi is our longitude, \theta is our latitude.

Cartesian coordinates can be obtained from spherical coordinates using the following relations:
x=R\, cos \theta \, cos \phi \\ y=R\, cos \theta \, sin \phi \\ z=R\, sin \theta

We're almost done, but we still need to take into account couple of factors, which arise due to the fact that in the geodesy the Earth is approximated with oblate spheroid or ellipsoid of revolution. So, when we talk about coordinates, we talk about coordinates on the surface of reference ellipsoid used in the geodetic datum, in this case, WGS 84 (hence, the distance is also measured between two points of reference ellipsoid). The factors are:

  • Since the Earth is flattened at the poles and bulges at the equator, the Earth radius is not constant and depends on the latitude of the point. Thus we need to compute it for both points and this can be done with the help of this calculator.

  • WGS 84 latitude of a point is geodetic latitude, which is determined by the angle between the equatorial plane and normal to the ellipsoid, as opposed to geocentric latitude, which is determined by the angle between the equatorial plane and line joining the point to the centre of the ellipsoid. Since the origin of our cartesian system is the center of the Earth, we need to convert geodetic latitude to geocentric latitude for both points.

We account for those using these formulas:
tan(\alpha)=\frac{b}{a}tan(\beta) \\ R =\sqrt{\frac{ (a^2cos(\beta))^2+(b^2sin(\beta))^2}{(a\,cos(\beta))^2+(b\,sin(\beta))^2}},
where \alpha is geocentric latitude, \beta is geodetic latitude, a - semi-major axis of the ellipsoid, b - semi-minor axis of the ellipsoid.

To summarize, to calculate the distance we should do the following:

  • Calculate Earth radius at each point
  • Calculate geocentric latitude at each point
  • Convert spherical coordinates of each point to cartesian coordinates, that is, from calculated radius, geocentric latitude and longitude to x,y,z.
  • Calculate distance using Euclidean distance formula