View Full Version : Maths Question
gavwvin
23-September-2005, 09:16 AM
How do I find the distance between 2 points on the surface of a sphere? I want to be able to find the distance between two locations on Earth given their longitude and latitude. I know how to find the distance by finding the arc length if could find the actual number of degrees the two are apart, but how do I do this? I suppose I'm trying to find the "hypotenuse" in degrees of a right angled triangle but projected onto the surface of a sphere. For short distances (<< radius of Earth) I presume it would look something like Pythagoras.
Thanks
JMV
23-September-2005, 09:56 AM
First get the angle difference of the longitudes alpha (lon1-lon2 in degrees)
[EDIT:This whole bracketed thing is completely it's wrong. I noticed it long after I had posted.
apply a=(2R^2(1-cos alpha))^1/2
where R is the radius of the earth 6370 km
then get the angle difference of the latitudes beta (lat1-lat2 in degrees)
apply b=(2R(1-cos beta))^1/2
From Pythagoras
c=(a^2+b^2)^1/2
where c is the lenght of a straight line from the two points
c=((R*sin alpha)^2+(R*sin beta)^2)^1/2
when alpha or beta < 90
but
replace alpha or beta or both with 180-alpha and 180-beta if alpha or beta or both >90 respectively
gamma=arccos((2R^2-c^2)/2R^2)
where gamma is the angle between the two points from the center of the earth
the distance d is
d=(gamma/360)*2pi*R ]
When figuring out the differences of the longitudes and latitudes you have to keep in mind the east/west , north/south markings
If two points are given
80 degrees N, 160 degrees W
and 85 degrees S, 170 degrees E
the difference of latitudes is actually 80+85=165 degrees
and with longitudes (180-160)+(180-170)=30 degrees
gavwvin
23-September-2005, 11:28 AM
Thanks, I managed to get a solution by using vectors instead (finding the vectors of the two locations from the centre of the Earth, then dot producting them to find the angle and multiplying by R to get the distance), yours may well come out to the same formula, (I tried multiplying it out to see if it is the same but ran out of paper- it gets rather hideous). Heres mine:
a1 = latitude a
b1 = latitude b
a2 = long a
b2 = long b
theta = angle between two locations
d = distance between locations
-------
cos(a1)cos(b1)cos(a2-b2) + sin(a1)sin(b1) = cos(theta)
d = R arccos(theta)
Tried with a couple of places and it looks like it works.
JMV
23-September-2005, 01:12 PM
Actually my solution above is wrong. I noticed that I had assumed the lines a and b to be perpendicular to each other but their not. It's actually the planes the lines a and b form with the center of the earth which are perpendicular to each other, not the lines themselves.
So when you have the angle differences alpha and beta you get the c from
c=((R*sin alpha)^2+(R*sin beta)^2)^1/2
And continue from there.
You don't need the lines a and b so forget them.
[EDIT: It's still wrong. I had assumed something else. Forget the whole thing. I'll try figuring out the right way.
Sorry about the misinfo.
hhEb09'1
23-September-2005, 07:54 PM
cos(a1)cos(b1)cos(a2-b2) + sin(a1)sin(b1) = cos(theta)
d = R arccos(theta)
Tried with a couple of places and it looks like it works.
I'm pretty sure that that last equation should be
d = R arccos(cos(theta))
(or just d = R theta) so that
d = R arccos(cos(a1)cos(b1)cos(a2-b2) + sin(a1)sin(b1))
When programming that, you should watch for exceptions. And remember that it applies to a spherical earth, whereas the earth is actually an oblate spheroid, so it is an approximation in that sense.
Saluki
23-September-2005, 07:55 PM
Couldn't this be done much more easily by converting degrees to radians? It would be a simple matter of finding the hypotenuse of a right triangle.
For example:
P1 = 49º N lat (0.8552 rad N Lat), 90º W Long (1.570 rad W Long)
P2 = 55º N Lat (0.9599 rad N lat), 95º W Long (1.658 rad W long)
Radius of Earth is about 6378.1 km
The difference in lat is 0.9599-0.8552 = 0.1047 rad
--> This is a north-south distance of 0.1047 * 6378.1 km = 667.8 km
The difference in Long is 1.658 - 1.570 = 0.088 rad
--> This is an east-west distance of 0.088 * 6378.1 km = 561.3 km
Now, the straight-line distance is sqrt[667.8² + 561.3²] = 872.3 km.
gavwvin
24-September-2005, 12:47 AM
hhEb09'1 yeah sorry thats what I meant and I accept that its approximate in that the Earth is not a sphere exactly but I think the effect of that is negligible
Saluki, Thats what I thought at first, but it is not a right angled triangle because it is projected onto a sphere... consider if one point was ant 0,0 (on the equator) another at 90,0 (on the equator) and another at 0,90 (at the pole) if it were a right angled triangle subject to pythagoras then the number of degrees between the pole and one of the points would be 90 * sqrt(2), which is nonsense because we know its 90. Also because the difference in longitude is not the change in angle from the centre of the Earth, again consider 0,150 and 0,30 (both at the pole), the angle between them is 0 not 120 degrees.
gavwvin
24-September-2005, 01:01 AM
Heres my derivation- maybe you can check it to see if I've got it right:
http://www.astronomyforbeginners.com/images/diagrams/mars_parallax_p.jpg
(sorry looks like you have to click for the images) vector OP is
http://www.astronomyforbeginners.com/images/equations/mars_parallax_vector.png
Where alpha is longitude and theta latitude. If we define OQ likewise we get a similar expression. The desired angle beta is the angle bewteen these two vectors, so we dot product the two:
unit vector OP . unit vector OQ = cos beta
which multiplies out to
cos alpha p * cos alpha q * cos theta p * cos theta q + cos alpha p * cos alpha q * sin theta p * sin theta q + sin alpha p * sin alpha q = cos beta
using compund angle formulae it simplifies to
cos alpha p * cos alpha q * cos(theta p - theta q) + sin alpha p * sin alpha q = cos beta
if we work in radians then distance between points d is:
d = R beta
where R is the radius of the earth so
d = R arccos(cos alpha p * cos alpha q * cos(theta p - theta q) + sin alpha p * sin alpha q)
Looks like it works OK- have I missed anything? I don't think I have to worry about whether its positive or negative because the scalar product gives the smallest (the non-reflex) angle between the vectors.
Enzp
24-September-2005, 07:22 AM
Or just call AAA.
Sam5
24-September-2005, 05:21 PM
Or just call AAA.
Lol, I was going to suggest he take a cloth tape measure and wrap it around the globe then convert the inches to miles.
Eroica
24-September-2005, 05:38 PM
Navigators used the Haversine Formula. (http://en.wikipedia.org/wiki/Haversine_formula)
hhEb09'1
24-September-2005, 06:05 PM
Lol, I was going to suggest he take a cloth tape measure and wrap it around the globe then convert the inches to miles.Hard to program into a computer though :)
Navigators used the Haversine Formula. (http://en.wikipedia.org/wiki/Haversine_formula)In that proof of the haversine formula, they derive gavwvin's formula, then say "As mentioned above, this formula is an ill-conditioned way of solving for c when c is small. Instead, we substitute the identity that cos(θ) = 1 − 2 haversin(θ), and also employ the addition identity cos(a − b) = cos(a) cos(b) + sin(a) sin(b), to obtain the law of haversines, above." Haversines are used to avoid the precision problems.
On the other hand, gavwvin's formula works pretty well for large c.
Saluki
25-September-2005, 04:52 PM
Saluki, Thats what I thought at first, but it is not a right angled triangle because it is projected onto a sphere... consider if one point was ant 0,0 (on the equator) another at 90,0 (on the equator) and another at 0,90 (at the pole) if it were a right angled triangle subject to pythagoras then the number of degrees between the pole and one of the points would be 90 * sqrt(2), which is nonsense because we know its 90. Also because the difference in longitude is not the change in angle from the centre of the Earth, again consider 0,150 and 0,30 (both at the pole), the angle between them is 0 not 120 degrees.
For relatively short distances (say less than 1000 miles apart), it should give a very reasonable approximation.
hhEb09'1
25-September-2005, 11:37 PM
For relatively short distances (say less than 1000 miles apart), it should give a very reasonable approximation.It seems like a good idea, doesn't it? :)
Couldn't this be done much more easily by converting degrees to radians? It would be a simple matter of finding the hypotenuse of a right triangle.
For example:
P1 = 49º N lat (0.8552 rad N Lat), 90º W Long (1.570 rad W Long)
P2 = 55º N Lat (0.9599 rad N lat), 95º W Long (1.658 rad W long)
Radius of Earth is about 6378.1 km
The difference in lat is 0.9599-0.8552 = 0.1047 rad
--> This is a north-south distance of 0.1047 * 6378.1 km = 667.8 km
The difference in Long is 1.658 - 1.570 = 0.088 rad
--> This is an east-west distance of 0.088 * 6378.1 km = 561.3 km
Now, the straight-line distance is sqrt[667.8² + 561.3²] = 872.3 km.However, the haversine formula (and Gavwvin's formula) gives 750.2 km, over 120 km less than your answer. The largest source of the discrepancy is that a degree of longitude gets smaller as you go farther north--the size decreases like the cosine of the latitude. You could just convert using the cosine of latitude, but which latitude? Point 1 or point 2? Using an average of the two seems reasonable, but then your formula starts to be more complex than Gavwvin's, and less accurate.
vBulletin® v3.8.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.
LinkBacks Enabled by
vBSEO 3.0.0