13
$\begingroup$

I've been reading around the net and everything I find is really confusing. I just need a formula that will get me 95% there. I have a tool that outputs the distance between two lat/long points.

Point 1: 32.773178, -79.920094 Point 2: 32.781666666666666, -79.916666666666671 Distance: 0.0091526545913161624 

I would like a fairly simple formula for converting the distance to feet and meters.

Thanks!

  • 0
    joriki's answer has an unqualified theta expression in the last formula: http://math.stackexchange.com/suggested-edits/36392011-12-22

4 Answers 4

10

The tool seems to be just calculating the Euclidean distance between the two points (the square root of the sum of the squared differences between the coordinates). This doesn't make any sense for latitudes and longitudes, which are not coordinates in a Cartesian coordinate system. Not only is this number not a meaningful distance, but it no longer contains the information required to reconstruct a distance from it, so you won't be able to calculate anything meaningful from it; you need to go back to the latitudes and longitudes themselves.

To calculate distances between points given by latitudes and longitudes precisely, you need to know which geoid was used as a reference in specifying them. But since you only want to get within 95% of the answer, you can safely assume that the Earth is a sphere.

There are two possible meanings for "the distance between two points" on a sphere. You can take the Euclidean distance between the two points (the actual points, not their latitude/longitude coordinates like your tool does), or you can take distance along the shortest curve along the surface of the Earth. Again, if you only want to get to within 95% of the answer and the distances are as small as in your example, the difference is negligble, so you can take the Euclidean distance, which is easier to calculate.

To get the Euclidean distance, you can first calculate the Cartesian coordinates of the points from their latitudes and longitudes. Denoting the latitude by $\theta$, the longitude by $\phi$ and the Earth's radius by $R$ (with $R\approx 6371 \mathrm{km}$), these are given by

$\vec{r}=\left(\begin{array}{c}x\\y\\z\end{array}\right) = \left(\begin{array}{c} R\cos\theta\cos\phi \\ R\cos\theta\sin\phi \\ R\sin\theta \end{array}\right)\;. $

Then you get the distance between them using

$d(\vec{r_1},\vec{r_2})=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2}\;.$

Since you seem to have small distances and aren't interested in precision, you can simplify this by expanding the trigonometric functions around one of the points, or, for greater precision, around the midpoint $\theta=(\theta_1+\theta_2)/2$, $\phi=(\phi_1+\phi_2)/2$:

$\vec{r_2}-\vec{r_1}\approx R\left(\begin{array}{c} \sin\theta\cos\phi(\theta_2-\theta_1)-\cos\theta\sin\phi(\phi_2-\phi_1) \\ \sin\theta\sin\phi(\theta_2-\theta_1)+\cos\theta\cos\phi(\phi_2-\phi_1) \\ \cos\theta(\theta_2-\theta_1) \end{array}\right)\;, $

${}$

$\lvert\vec{r}_2-\vec{r}_1\rvert\approx R\sqrt{(\theta_2-\theta_1)^2 + \cos^2\theta(\phi_2-\phi_1)^2}\;.$

5

I'm not entirely sure what the distance number your tool is returning means, but here is one way to go about computing the distance you want.

Below is the Spherical Law of Cosines as it appears in UCSMP Functions, Statistics, and Trigonometry, 3rd ed., copied here because the diagram is good and helps with clarity.

Spherical Law of Cosines (from UCSMP Functions, Statistics, and Trigonometry, 3rd ed.)

If $\triangle ABC$ is a spherical triangle with arcs $a$, $b$, and $c$ (meaning the measures of the arcs, not the lengths), then $\cos c=\cos a\cos b+\sin a\sin b\cos C$.

Now, to the specific problem at hand. Let's use the diagram below, also from UCSMP Functions, Statistics, and Trigonometry, 3rd ed., for reference.

globe (from UCSMP Functions, Statistics, and Trigonometry, 3rd ed.)

Let $A$ and $B$ be the two points between which you want to find the distance (for simplicity, I'll assume they are both in the northern hemisphere, and leave extending the solution to any points as an exercise); $N$ and $S$ are the north and south poles, respectively; $C$ and $D$ are the points on the equator that are on the same line of longitude as $A$ and $B$, respectively. Consider spherical $\triangle ABN$. $a=(90°-\text{latitude of point }B)$; $b=(90°-\text{latitude of point }A)$. $N=\text{positive difference in longitude between points }A\text{ and }B$. Use the Spherical Law of Cosines ($\cos n=\cdots$ form) to determine $n$, which is the shortest arc between the two points.

If, for example, $n=10°$, the diameter of the earth is about 12756.2 km, so the distance is $\frac{10°}{360°}\pi\cdot 12756.2\approx 1113.2\text{ km}$.

(graphics from Lesson 5-10 of UCSMP Functions, Statistics, and Trigonometry, 3rd ed., © 2010 Wright Group/McGraw Hill)

4

If the distances are small, you can use the linearized version: $\Delta x=R \cos(\theta)\Delta \phi, \Delta y=R \Delta \theta$, where $x$ is east-west distance, $\theta$ is latitude (measured with zero at the equator), $y$ is north-south distance, and $\phi$ is longitude. Then the distance is $d=\sqrt{\Delta x^2+ \Delta y^2}$ in whatever units you used for $R$.

3

Since the question is tagged Mathematica it might be good to provide the Mathematica function, which is (as of version 7):

GeoDistance[{32.773178, -79.920094},              {32.781666666666666,-79.916666666666671} ]  ==> 994.652 

or, if you want to specify the reference ellipsoid:

GeoDistance[    GeoPosition[{32.773178, -79.920094, 0}, "ITRF00"],     GeoPosition[{32.781666666666666, -79.916666666666671 , 0}, "ITRF00"] ]  
  • 0
    @J.M. It might have been once but it's a built-in function now.2011-05-08