[GIS] Compute distance between two point from longitude, latitude & height

coordinatesdistance

I am currently trying to compute the real distance between two 3D points (on a WS84 ellipsoid represensation of our earth), but my knowledge in Geographic Information System is pretty nil (except the fact that I know about using geodesic distance instead of the classic sqrt).

What I use can already compute the geodesic distance between two pair of longitude / latitude, it does not however provide the 3D distance.

So I though about using the classic sqrt distance formula using the result of the geodesic distance and the height, is this approach right ?

I can use either the raw mathematica formula, or one that use the current geodesic distance with the difference of elevation.

Note : I obviously tryed to google it, but I only end up on full of article about building 3D mesh using geodesic distance. So I am wondering also if I am really using the right word when searching for "geodesic distance between 3D points".

I checked this from a post given by the tool that suggest question to check but as it seems it ignores the elevation differences : http://www.movable-type.co.uk/scripts/gis-faq-5.1.html

Best Answer

If I understood correctly, by "real distance" you mean the distance along an actual 3D straight line connecting your two points. The term "geodesic" refers to a straight line on the curved ellipsoid surface.

Using the pythagorean theorem with the geodesic length and the height difference would not work, because the geodesic line is curved, it is not a square triangle with straight segments.

To calculate a 3D straight distance from lat/lon/ht, you will first need to convert your points to 3D cartesian coordinates (see formulas below). For modern reference systems like WGS84/ITRF2014, the reference frame is called an ECEF (Earth-Centered, Earth-Fixed). Then you will be able to calculate the distance with the square root method in 3D and get the correct answer. However keep in mind that a straight line in 3D, over long distances, can pass through the Earth, so this calculation is mainly useful for 3D "line of sight" types of problems for generally short distances.

Also, make sure you are using ellipsoidal heights, not altitudes above sea level or geoid level, since this could slightly alter the distances. If you need to convert from geoidal (mean sea level) to ellipsoidal, this tool can be useful.

Let's write the lat, lon, ht of a point as phi, lambda, h. You can find the X, Y, Z coordinates of the point like this :

X = (N(phi)+h) * cos(phi) * cos(lambda)

Y = (N(phi)+h) * cos(phi) * sin(lambda)

Z = ((b^2/a^2) * N(phi) + h) * sin(phi)

Where :

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

a = semi-major axis (6,378,137 m)

b = semi-minor axis (6,356,752.314245 m)

e^2 = 1 - (b^2 / a^2)

Then with pythagorean in 3D, we find the distance d:

d = sqrt{(X_2-X_1)^2 + (Y_2-Y_1)^2 + (Z_2-Z_1)^2}