Associated Topics || Dr. Math Home || Search Dr. Math

### Determining Distance between Two Cities

```
Date: 07/30/97 at 16:10:59
From: Danna Remen
Subject: Equation for determining distance between 2 cities using
longitude and latitude

I need an equation to use in an application for a car dealership.
When a dealer does not have the particular car that a customer wants,
the dealer should be able to find out which dealerships in other
cities have the car (using what we call a Car Locator), and how far
away (in miles) each location is.  I have tried doing this using what
is apparently a faulty equation using longitude and latitude. All
distances are in the thousands of miles, even between cities within
the same state. Do you have anything that I can use?
```

```
Date: 07/31/97 at 09:00:09
From: Doctor Jerry
Subject: Re: Equation for determining distance between 2 cities using
longitude and latitude

Hi Danna,

Here's some information about calculating great circle distances,
using latitude and longitude, and assuming the Earth is a sphere.

I'll give the answer using spherical coordinates. It's quite easy to
convert to latitude and longitude coordinates. In a right-handed
coordinate system, let (x,y,z) be a point on a sphere of radius a.
The spherical coordinates of (x,y,z) are (a,phi,theta), where phi is
like latitude, but it is measured from the positive z-axis. The angle
phi varies between 0 and pi. The angle theta is like longitude, but is
measured from the positive x-axis (towards the positive y-axis). The
angle theta varies between 0 and 2*pi.

Suppose you have the spherical coordinates (a,phi,theta) of a point.
The angle phi is like latitude, but it is measured from the positive
z-axis. The angle phi varies between 0 and pi. The angle theta is like
longitude, but is measured from the positive x-axis (towards the
positive y-axis). The angle theta varies between 0 and  2*pi.

Given (a,phi,theta), calculate the (x,y,z) coordinates from

x=a*cos(theta)*sin(phi)
y=a*sin(theta)*sin(phi}
z=a*cos(phi).

So, suppose you are given the points (a,phi_1,theta_1) and
(a,phi_2,theta_2). The first thing to do is to calculate the
rectangular coordinates r_1=(x_1,y_1,z_1) and r_2=(x_2,y_2,z_2) of
these points.

Letting alpha be the angle between the lines joining the center
(0,0,0) of the sphere to r_1 and r_2, use the dot product of the
vectors r_1 and r_2 to calculate alpha.

You will find that

alpha= arccos(r_1.r_2/a^2) = arccos(cos(phi_1)*cos(phi_2)
+cos(theta_1-theta_2)*sin(phi_1)*sin(phi_2)).

The great circle distance between r_1 and r_2 is

d=a*alpha.

-Doctor Jerry,  The Math Forum
Check out our web site!  http://mathforum.org/dr.math/
```
Associated Topics:
High School Geometry
High School Higher-Dimensional Geometry

Search the Dr. Math Library:

 Find items containing (put spaces between keywords):   Click only once for faster results: [ Choose "whole words" when searching for a word like age.] all keywords, in any order at least one, that exact phrase parts of words whole words

Submit your own question to Dr. Math
Math Forum Home || Math Library || Quick Reference || Math Forum Search

Ask Dr. MathTM
© 1994- The Math Forum at NCTM. All rights reserved.
http://mathforum.org/dr.math/