forum-msg-id-131860-edit

Original date:2018-01-31 19:06:39 Edited by: Senator Subject: Re: distance point to point revisited

This function seems to be a more accurate than the Great Circle Method, but I didn't know how to translate min(1,sqrt(a)) to euphoria: c = 2 * arcsin(min(1,sqrt(a)))

See: Haversine Formula and Calc-Distance

global function distance(atom LA1, atom LO1, atom LA2, atom LO2, integer miles = 1) 
-- Haversine Formula  
 
atom a, c, D, DLO,  DLA, R = 6371.02 -- mean earth radius in km 
 
    DLO = deg2rad(LO2-LO1)  DLA = deg2rad(LA2-LA1) 
    LA1 =  deg2rad(LA1)  LO1 = deg2rad(LO1) -- initial location coordinates  
    LA2 =  deg2rad(LA2)  LO2 = deg2rad(LO2) -- destination location coordinates 
 
    a = power(sin(DLA/2),2)  + cos(LA1) * cos(LA2) * power(sin(DLO/2),2) 
    c = 2 * arcsin(min({1,sqrt(a)})) 
    D = R * c 
    
    if miles then 
        D/=1.609      -- convert km to miles   
    end if 
     
return D 
end function 
 
 
-- test 
-- the distance reading refers to the Haversine Formula 
 
LA1=32.204287 LO1=82.322732 -- Lyons, GA - starting location 
 
LA2=32.0835 LO2=81.0998   -- Savannah, GA USA  -- 72.0542 
? Great_Circle_Distance(LA1,LO1, LA2, LO2,u)   -- 72.12361789                  
? distance(LA1,LO1, LA2, LO2,u)                -- 72.04468674                    
         
LA2=21.3069 LO2=157.8583 -- Honolulu, USA      -- 4627 
? Great_Circle_Distance(LA1,LO1, LA2, LO2,u)   -- 4636 
? distance(LA1,LO1, LA2, LO2,u)                -- 4631                              
         
LA2=51.5074 LO2=0.1278 -- Lyons, GA to London, UK -- 4195 
? Great_Circle_Distance(LA1,LO1, LA2, LO2,u)      -- 4202                            
? distance(LA1,LO1, LA2, LO2,u)                   -- 4198                                        
         
LA2=-22.9068 LO2=43.1729-- Lyons, GA to Rio de Janero -- 4599 
? Great_Circle_Distance(LA1,LO1, LA2, LO2,u)          -- 4608.276053                                   
? distance(LA1,LO1, LA2, LO2,u)                       -- 4603.232816                                                       
 
 
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu