# Calculating straight-line distance between cities

1. Aug 30, 2015

### Nathanael

Suppose we know the (longitude/latitude) coordinates of two cities and we want to find the straight-line distance between them. Call this distance B.

Would this be correct?

$B=\sqrt{B_1^2+B_2^2}$
$B_1=2R\sin(\theta / 2)$
$B_2=2R\sin(\phi / 2)$
Where:
θ and Φ are the difference between the longitude/latitude coordinates respectively.

Seems correct to me, but I have an astronomy lab where the coordinates of two cities are given and the (straight-line) distance between them is given, but it doesn't agree with my formula above.

2. Aug 30, 2015

### sophiecentaur

Off the top of my head, I should have expected the latitude to be included in the calculation for the distance between lines of longitude. Your formula seems to assume that the distance between lines of longitude is the same from equator to pole. (no spherical effects) I did all this once in a Nav course and once in a propagation programme for HF broadcasting but it's all gone!!!
At first, I thought "great circle" but, of course, for Astronomy, you really do want the straight line distance.

3. Aug 30, 2015

### Staff: Mentor

Are you looking for the "straight-line" distance across the curved surface of the earth (the distance you'd cover if you walked from one city straight towards the other) or the straight-line path that goes through the earth?

Either way, the same $\theta$ value corresponds to different distances according to how far from the poles you are. You're not taking that effect into account.

4. Aug 30, 2015

### andrewkirk

I doubt it would be that, because the formula is symmetric in $\theta$ and $\phi$ but their roles in the spherical coordinates are not symmetric. If $\theta$ is the azimuth then it relates to a smaller circle (non-great circle) than $\phi$.

I think the correct formula will be based on doing the 3D geometry to work out the angle $\angle C_1OC_2$ where $C_1,C_2$ are the locations of the two cities on the sphere and $O$ is the centre. Then the distance is just $R \angle C_1OC_2$.

Edit: I just saw Nugatory's post. I had assumed by 'straight line' you meant the great circle distance, but as he points out, you may mean the straight line in $\mathbb{R}^3$, for which a different formula would apply, but again I would not expect it to be symmetric in $\theta,\phi$.

5. Aug 30, 2015

### Nathanael

Ok, thanks everyone. Yes I meant the straight-line distance through space, not the curved path along the surface.

Let us use $Φ_1$ $θ_1$ and $Φ_2$ $θ_2$ for each city. (Φ is latitude so Φ=0 is on the equator.)

If Φ_1 = Φ_2, it would be:
$B=2R\cos(Φ)\sin\big(\frac{\left |θ_2-θ_1\right |}{2}\big)$

If θ_1 = θ_2 it would be:
$B=2R\sin\big(\frac{\left |Φ_2-Φ_1\right |}{2}\big)$

I'll have to think more about how to put it together when both coordinates are different. I can't use pythagoreans theorem as I don't believe they would be perpendicular (unless φ=0 for one of the cities).

Thanks again, I'll think about it.

6. Aug 30, 2015

### andrewkirk

The coordinates of $C_i$ are $z_i=R\cos\phi_i,\ x_i=R\sin\phi_i\cos\theta_i,\ y_i=R\sin\phi_i\sin\theta_i$.
The straight line distance will be

$$d=\sqrt{(z_2-z_1)^2+(y_2-y_1)^2+(x_2-x_1)^2}$$

Substituting the formulas from the first line into that gives the answer. I imagine some simplification is possible.

Further, although this isn't what you're after, the great circle distance will be

$$R\sin^{-1}\frac{d}{2R}$$

Last edited: Aug 30, 2015
7. Aug 30, 2015

### Nathanael

Good point, converting to cartesian then using pythaogrean is a straightforward solution, thanks Andrew.