Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating straight line distances 1

Status
Not open for further replies.

bdenson

Programmer
Dec 12, 2001
14
GB
Given the Latitude and Longtitude of two points, and the radius of the Earth in miles, I need to work out the distance between the two points.

I have been given the calulations

Lat1=52.47758N Lon1=1.90983W
Lat2=50.80029N Lon2=1.08825W
Delta of Lat (Dlat)=Lat2-Lat1
Delta of Lon (Dlon)=Lon2-lon1
a={sin(Dlat/2)}^2 + [cos(lat1) * cos(lat2) * {sin(dlon/2)}^2]

c=2*arcsin(min1,sqrt(a))
d=Radius*c

d being the distance between the two points. I have tried to write this forumla in Foxpro, but I'm getting 5430 miles instead of around 124 miles.

Can anyone help?

Barry Yesterday is history
Tomorrow is a mystery
and todays a gift... ...thats why we call it the present.
 
The trig functions in VFP are expressed in radians. Could this be the problem? "I like work. It fascinates me. I can sit and look at it for hours..."
 
Another useful document (for UK Ordnance Survey based co-ordinates)is "A guide to co-ordinate systems in Great Britain" which can be obtained from:


This has the formulae for converting from longitude/latitude to eastings/northings (and vice-versa) and also for converting OS grid references (eg SN123456) to eastings/northings, based on different projections and ellipsoids.

Neil "I like work. It fascinates me. I can sit and look at it for hours..."
 
Barry,

What is Min1?

Why would ArcSin need two parameters?

Regards

Griff
Keep [Smile]ing
 

Is this the right formula?

Code:
CLEAR
Lat1=52.47758
Lon1=1.90983
Lat2=50.80029
Lon2=1.08825
Dlat=Lat2-Lat1
Dlon=Lon2-lon1
a=(sin(dtor(Dlat/2)))^2 + (cos(dtor(lat1)) * cos(dtor(lat2)) * (sin(dtor(dlon/2)))^2)

Radius = 4214.618316927 
c=2*asin(sqrt(a))
d=Radius*c

? d

It yields about 128

Regards

Griff
Keep [Smile]ing
 
PS,

If you assume just 4000 miles for the radius, you get an answer closer to the one you mentioned!

HTH Regards

Griff
Keep [Smile]ing
 
Thanks Guys!!!

Problem solved now.

Got a solution from FoxTalk - Thanks Mike

FYI - Griff, You solution works too.

Thanks Again

Barry Yesterday is history
Tomorrow is a mystery
and todays a gift... ...thats why we call it the present.
 
Could you send me the text of the FoxTalk article you found. I tried to look at it, but could get into it. Thanks,

Bill
 
BillGravell

The arctical is called "Calculate the distance between two points" (July 1998). Do a search in FoxTalk's past issues for "Distance" (w/o quotes) you should find it. Although it is for members, the online membership if free. Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top