Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Spheroidal long-lat distance calculation
Message
 
 
To
15/02/2007 17:00:37
Mike Yearwood
Toronto, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01196313
Message ID:
01196324
Views:
12
May be the old discussion can help a little
Re: Distance calculation by lattitude/longitude Thread #1052304 Message #1052330

>Hey all
>
>I've been trying to use the third formula on this page:
>
>http://en.wikipedia.org/wiki/Great-circle_distance
>
>The formula is unnamed, but is indicated as being the most accurate.
>
>My trig is pretty rusty, and I don't think I ever did it on a sphere. :)
>
>I'm plugging in the sample lat-long for BNA and LAX and I'm not getting the same results.
>
>I've converted everything to radians. They name a formula in the "worked example" but that name is not referenced elsewhere on the page, so I'm not even sure which formula they're trying to demonstrate.
>
>Can anyone show me what I'm missing?
>
>Thanks!
>
>
CLEAR
>SET DECIMALS TO 5
>
>m.lat1 = 36.12
>m.long1 = -86.67
>?"lat1",m.lat1,"long1",m.long1
>
>m.lat2 = 33.94
>m.long2 = -118.40
>?"lat2",m.lat2,"long2",m.long2
>
>m.DeltaSigma = MyDistance(m.lat1,m.long1,m.lat2,m.long2)
>
>?"delta-sigma",m.DeltaSigma
>
>m.Dist = m.DeltaSigma * 6372.795
>?m.Dist
>RETURN
>
>
>FUNCTION myDistance
>LPARAMETERS m.lat1, m.long1, m.lat2, m.long2
>LOCAL m.rlat1, m.rlong1, m.rlat2, m.rlong2
>
>m.rlat1 = DTOR(m.lat1)
>m.rlong1 = DTOR(m.long1)
>?"rlat1",m.rlat1,"rlong1",m.rlong1
>
>m.rlat2 = DTOR(m.lat2)
>m.rlong2 = DTOR(m.long2)
>?"rlat2",m.rlat2,"rlong2",m.rlong2
>
>m.DeltaLong = m.long2 - m.long1
>
>m.rDeltaLong = DTOR(m.DeltaLong)
>
>m.DeltaSigma = ;
>  atan( ;
>    SQRT(;
>      (COS(m.rlat2) * SIN(m.rDeltaLong))^2 + ;
>      (COS(m.rlat1) * SIN(m.rlat2) - SIN(m.rlat1) * COS(m.rlat2) * COS(m.rDeltaLong))^2;
>    ) ;
>    / ;
>      (SIN(m.rlat1) * SIN(m.rlat2)) + (COS(m.rlat1) * COS(m.rlat2) * COS(m.rDeltaLong)) ;
>  )
>
>return m.DeltaSigma
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform