php - Inaccuracies with Sperical Law of Cosines...specifically along latitude? -


i have strange problem using cosine formula in php application..

function calculatedistancecosine($deca, $decb) {     $lon1 = $deca[0]; //this equal point a's longitude, , on..     $lat1 = $deca[1];      $lon2 = $decb[0];        $lat2 = $decb[1];      //echo $lon1." ".$lat1."<br/>";     //echo $lon2." ".$lat2."<br/>";      $distance  = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon2-$lon1));     $distance  = acos($distance);     $distance  = rad2deg($distance);     $distance  = $distance * 60 * 1.1515;     $distance  = round($distance, 4);      return $distance;    } 

my input this:

45.468055555556 -73.741388888889 //- coordinates montreal international airport 28.428888888889 -81.315833333333 //- orlando international airport 

however, upon using it, wild mistakes.. i.e, "the distance montreal orlando 576 km -- wrong."

what's interesting is accurate along longitude axis. example, if gave input of:

50 -73.741388888889  50 -81.315833333333  

the error 50km, acceptable.

in other words, why neglecting latitudinal differences?

i've tried harvesine formula similar results unfortunately.

i believe main problem you're getting latitude confused longitude. you've not shown code that's wrong, bear in mind in arrays, need longitude first, followed latitude, function work. in example you've given, you've listed latitude first, followed longitude.

your code work out distance between 2 points written 576 (in units i'll mention in minute), points aren't think :) try changing function follows:

$lat1 = $deca[0]; //this equal point a's *latitude*, , on.. $lon1 = $deca[1];  $lat2 = $decb[0];    $lon2 = $decb[1]; 

...or pass in values in expected order.

also, don't recognise distance multiplier, looks might calculating result in miles, not kilometres. kilometres, try:

$distance  = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon2-$lon1)); $distance  = acos($distance); $distance  = $distance * 6372.8; $distance  = round($distance, 4); 

(it's skipping conversion degrees , multiplier that's changed, basic formula remains same.)

given above changes, distance works out @ around 2,008 kilometres. right? i'm afraid i've never visited montreal, orlando, or anywhere in between...


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -