Getting started with geographical coordinates

Graham Samuel livfoss at mac.com
Sun Apr 5 16:03:48 EDT 2020


I’ve been trying these formulae out, and I’ve been using the info on https://www.movable-type.co.uk/scripts/latlong.html - for my purposes (distances from say 100 metres to up to a few kilometers) I think this works as well as haversine, but maybe not for every kind of measurement. The function gives a result in kilometres starting from coordinates in degrees. Seems to work, but I need to do a bit more work on the (real) ground to convince myself.

 function distanceslc lat1,lon1,lat2,lon2

constant k1 = 0.017453 -- that's pi/180

-- This implements the spherical law of cosines, from movable-type.co.uk. Confirmed with his javascript version

return acos(sin(lat1*k1) * sin(lat2*k1) + cos(lat1*k1)*cos(lat2*k1)*cos(lon2*k1-lon1*k1))*6371

end distanceslc


Graham

> On 4 Apr 2020, at 16:47, Ralph DiMola via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> A friend of mine turned me on to this 10 years ago. This is the Haversine
> formula. It assumes that the earth is sphere and is not very accurate for
> very small distances. I have not tried to use the Vincenty's formula that
> does better. For general purposes the HF should be sufficient.
> 
> Just give me the credit for LC implementation of a friends of mines routine.
> Although I understand how it works the real credit goes to Don Josef de
> Mendoza y Rios in 1796.
> 
> The girls and boys doing math in that period really set the stage. This
> brought me back to my CGI days when I was patting myself on the back when I
> self learned(with a friends help after reading the Kreyszig) how to move
> points in space and calculate lighting.  I then self reflected and realized
> that I was just putting together the pieces of math that these folks created
> out of thin air. I still felt like I accomplished something but very much
> smaller the scheme of things.
> 
> Ralph DiMola
> IT Director
> Evergreen Information Services
> rdimola at evergreeninfo.net
> 
> -----Original Message-----
> From: use-livecode [mailto:use-livecode-bounces at lists.runrev.com] On Behalf
> Of Bob Sneidar via use-livecode
> Sent: Friday, April 03, 2020 5:31 PM
> To: How to use LiveCode
> Cc: Bob Sneidar
> Subject: Re: 
> 
> Ralph, this is brilliant. I remember trying to do something similar years
> ago, and giving up because I didn't know how to do the math. I suck at math,
> or rather I am too lazy and impatient to work the problem. 
> 
> Bob S
> 
>> On Apr 3, 2020, at 14:27 , Ralph DiMola via use-livecode
> <use-livecode at lists.runrev.com> wrote:
>> 
>> Graham,
>> 
>> This my distance calculation for what it's worth.
>> 
>> Function distance lat1, lon1, lat2, lon2, unit
>>  -- Calculate Distance between to points
>>  --
>>  --lat1, lon1, lat2, lon2 are in deg.fractionalDegrees
>>  -- Unit
>>  --     if empty then miles
>>  --     K = kilometers
>>  --     N = nautical miles
>>  local theta
>>  local dist
>> 
>>  Put lon1 - lon2 into theta
>>  put Sin(deg2rad(lat1)) * Sin(deg2rad(lat2)) + Cos(deg2rad(lat1)) *
> Cos(deg2rad(lat2)) * Cos(deg2rad(theta)) into dist
>> 
>>  put Acos(dist) into dist
>>  put rad2deg(dist) into dist
>>  put dist * 60 * 1.1515 into dist
>> 
>>  switch unit
>>     case "K"
>>        put dist * 1.609344 into dist
>>     case "N"
>>        put dist * 0.8684 into dist
>>  end switch
>> 
>>  Return dist
>> 
>> End distance
>> 
>> 
>> Function rad2deg rad
>>  Return rad / PI * 180.0
>> end rad2deg
>> 
>> 
>> Ralph DiMola
>> IT Director
>> Evergreen Information Services
>> rdimola at evergreeninfo.net
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list