38

Many people when first trying to calculate distances between two longitude / latitude pairs ask if Pythagorean theorem works as an appropriate distance function.

Most often people answer "no, the Pythagorean theorem only works on a 2D Euclidean plane." Rarely, however, do people mention the effect of scale and location on the sphere on how inaccurate the Pythagorean theorem is.

The basic idea being at very small scales, the surface of a sphere looks very much like a plane. At very large scales, it distances along the surface are more curved and therefore the difference between the incorrect Pythagorean Theorem and the correct Haversine Formula is greater.

Does anyone know a formula or rule of thumb that tells you the difference between the two distance measures based on the scale of the distance you are trying to measure?

I think having this explicitly would help in:

  1. explaining why the Pythagorean Theorem isn't perfect; and
  2. in letting people who are looking for more "rough" distances know when Pythagoras actually will serve their purposes.
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Amos Budde
  • 503
  • 1
  • 4
  • 7

3 Answers3

42

Using the Pythagorean formula on positions given in latitude and longitude makes as little sense as, say, computing the area of a circle using the formula for a square: although it produces a number, there is no reason to suppose it ought to work.

Although at small scales any smooth surface looks like a plane, the accuracy of the Pythagorean formula depends on the coordinates used. When those coordinates are latitude and longitude on a sphere (or ellipsoid), we can expect that

  1. Distances along lines of longitude will be reasonably accurate.

  2. Distances along the Equator will be reasonably accurate.

  3. All other distances will be erroneous, in rough proportion to the differences in latitude and longitude.

The error depends on the start and end point of the distance calculations. However, because both the sphere and ellipsoid have a circular symmetry around the axis, the error depends only on the difference of the longitudes, so to study this error we might as well take the point of origin to be at the Prime Meridian. Because both the sphere and ellipsoid are symmetric under a north-south reflection, we only need to study points of origin in the southern hemisphere. For any such point we may draw a contour map of the relative error, equal to [Pythagorean calculation] / [True distance].

The Pythagorean formula, using the mean radius of the earth, is

Pythagorean distance =  6371000. * Sqrt[dx^2 + dy^2]] * pi / 180 meters

where dx is the difference in longitudes and dy is the difference in latitudes, both in degrees. (The difference in longitude values is reduced modulo 360 to give the correct value of dx when crossing the antimeridian; not doing so would introduce artificially large errors that tell us nothing about the Pythagorean formula itself.)

The following plots show the relative error compared to the correct distance on the WGS 84 ellipsoid for latitudes from -70 to 0 in increments of 10 degrees. The horizontal coordinate is the difference in longitudes and the vertical coordinate is the latitude of the destination. Light regions have relatively small error: the contour lines are at 1, 1.01, 1.02, 1.05, 1.1, 1.2, 1.5, 2, etc. (The pure white areas in the corners are places where the error goes beyond the range of these contours.) The red dots show the point of origin.

Plots

The vertical white bands testify to the correctness of expectation (1): Pythagorean distances are accurate when there is a small difference in longitudes. The horizontal white bands at low latitudes confirm expectation (2): near the Equator, horizontal distances are reasonably accurate. Otherwise, as witnessed by the extensive darker regions, at all other distances the Pythagorean formula is bad.


We can make quantitative estimates of the maximum error attained for pairs of nearby points (within, say, a few hundred kilometers of each other). Scale--using an appropriate value for the radius--is true along the meridian but along a circle of latitude it errs approximately by the secant of the latitude. For example, at a latitude of 40 degrees the secant is 1.31, implying the Pythagorean formula will give distances about 31% too large in the east-west direction. (This is evident in the upper right contour plot, for a point of origin at -40 degrees latitude, where the region immediately east-west of the red dot lies between the 1.2 and 1.5 contours.) Short distances in all other directions will be too large by some amount between 0% and 31%; longer distances may err by even more (as the contour plots show).

whuber
  • 69,783
  • 15
  • 186
  • 281
  • 1
    There really needs to be a 'favorite answer' functionality, for answers like these. – Devdatta Tengshe Apr 21 '13 at 04:10
  • One point which I don't see addressed in your answer is what happens when the two points are on either side of the International Date Line.(-180). Euclidean distance gives tremendously large values, while the correct distance is much less. – Devdatta Tengshe Apr 21 '13 at 05:40
  • I interpreted the use of "Pythagorean distance" in the question as the distance between two positions in 3 dimensions. In that case, the question isn't so silly and my answer follows. – cffk Apr 21 '13 at 15:36
  • 2
    @DevdattaTengshe: he explicitly requires it to be sane: "where dx is the difference in longitudes (expressed between -180 and 180) and dy is the difference in latitudes, both in degrees." – lynxlynxlynx Apr 21 '13 at 17:11
  • @lynxlynxlynx: Try to find out the dx between (0N 179E) & (0N 179W) and see what result you get in both of them. – Devdatta Tengshe Apr 22 '13 at 02:54
  • 1
    That's 2, since 2*179 is greater than 180? – lynxlynxlynx Apr 22 '13 at 08:36
  • @Devdatta The formula is to compute the difference modulo 360 with an offset of -180. Because 179E = +179 and 179W = -179, the offset from 179W to 179E is dx = mod(179 - (-179) + 180, 360) - 180 = mod(538, 360) - 180 = 178 - 180 = -2. – whuber Apr 22 '13 at 12:40
  • 1
    @whuber: I know this and you know this, but most people who blindly try to use Pythagorean/Euclidean geometry, do not even think or know about it. It would help if this fact (you should use Mod 360) was present in your answer. – Devdatta Tengshe Apr 22 '13 at 13:45
  • @Devdatta I will make that clarification. – whuber Apr 22 '13 at 14:33
  • @whuber My only consideration is that you are using the euclidean distance using as coordinates the lattitude and londtitude as points to the cartesian plane. I was expecting first to transform shperical coordinates to the cartesians ones with the aid of cylindrical ones and then compute the euclidean distance...this approach seems more accurate – curious Mar 28 '14 at 17:09
  • @curious It sounds like you may be talking about another kind of projection. (Using lat-lon as if they are Euclidean is tantamount to applying an Equirectangular or Plate Carree projection, which is cylindrical.) The accuracy will depend on the projection but all global projections will introduce large errors. – whuber Mar 28 '14 at 18:59
  • @whuber but you are using them as they are as i can see from the math expression – curious Mar 29 '14 at 01:59
  • @curious I suspect you might appreciate what is going on if you would study projections a little more. Take a look in particular at the equations for the Equirectangular Projection. – whuber Mar 29 '14 at 20:21
  • @whuber - at a latitude of 40 degrees the secant is 1.31 ... is easily corrected by multiplying longitude distance by cos(lat). Where lat = average(lat1, lat2). I certainly hope no one uses pythagorean formula without that adjustment! – ToolmakerSteve Nov 24 '18 at 17:31
  • 1
    @ToolmakerSteve That's fine--I often use this correction--but would hope its user understands it is an approximation and for large distances and a few other circumstances it can be far off the mark. – whuber Nov 24 '18 at 19:51
8

I interpreted "Pythagonean distance" as "Euclidean distance". Then the answer is the same as "what is the difference between the length of a chord of a circle and the subtended perimeter?" Let radius be R, subtended angle is A (radians).

perimeter = L = A*R
chord = C = 2*sin(A/2)*R
diff = D = L - C
     = (A-2*sin(A/2))*R
     = A^3/24 * R  (for A small)
     = L^3/(24*R^2) (eliminating A)
relative error = D/L
               = (L/R)^2/24

For the earth, substitute R = 6400 km. By the way, call it "great circle distance" (what it is) not "haversine distance" (how it is calculated). (This is similar to the distinction between Pythagorean distance and Euclidean distance.)

cffk
  • 3,271
  • 18
  • 24
6

For a full and rigorous answer look to whuber's answer above. I'm going to answer in a more visual and basic way.

The reason why planar/Pythagorean calculations are inappropriate is because the calculations rely on the fact that moving one step in any direction is a constant change in magnitude regardless of where you are on the graph.

plain graph

Longitude doesn't conform to this requirement. Lines of longitude converge at the poles.

globe showing convergence

That is why when we flatten the Earth to reflect the rules of a planar graph we get distortion.

Mercator projection map

If you look at that map it appears as if Greenland is roughly the size of Africa and Antarctica is about the size of Eurasia. Of course that isn't true. Greenland and Antarctica are both extremely distorted because they're close to the poles where longitude converges.

northern hemisphere globe view

As you can see Greenland is approximately the size of Mexico.

southern hemisphere glove view

And Antarctica is about the size of southern Africa (not South Africa).

As you can see the errors you'll get applying Pythagorean formulas depend more on where the points are than the distance between the points. With the important caveat that longer distances will magnify any errors. This is why planar solutions, while tempting, are a poor choice. Distortions will bite you and it isn't as simple as an offset. The errors are a result of warping the earth to fit inappropriate rules.

Erik
  • 309
  • 3
  • 11
  • Actually, what you are showing is a different type of error. Used correctly, pythagorean theorem calculates longitude distance based on the length along the line of latitude you are at, so multiplied by cos(lat). Used this way, errors are small for small distances, anywhere on a sphere (except if pass N or S pole). What you are showing is a distortion of a projection of the whole earth, where inevitably some regions are hugely distorted. "the errors you'll get .. depend more on where .. than the distance" is not true if use * cos(lat). – ToolmakerSteve Nov 24 '18 at 17:24