我有一個從位置(經度)和到位置(經度,緯度)。經過計算,它應該告訴我什麼是使用指南針最接近的方式。下面是PHP代碼來做到這一點,但它顯示了錯誤的方向,我需要一點幫助。複雜的數學與大圓公式
function GreatCircleDirection ($OrigLat, $DestLat, $OrigLong, $DestLong, $Distance)
{
$Result = 0.0;
$L1 = deg2rad($OrigLat);
$L2 = deg2rad($DestLat);
$D = deg2rad($Distance/60); # divide by 60 for nautical miles NM to degree
$I1 = deg2rad($OrigLong);
$I2 = deg2rad($DestLong);
$Dlong = $I1 - $I2;
$A = sin($L2) - cos($D + $L1 - pi()/2);
$B = acos($A/(cos($L1) * sin($D)) + 1);
if ((abs($Dlong) < pi() and $Dlong < 0) or (abs($Dlong) > pi() and $Dlong > 0))
{
//$B = (2 * pi()) - $B;
}
$Result = $B;
return rad2deg($Result);
}
function GreatCircleDistance ($OrigLat , $DestLat, $OrigLong, $DestLong)
{
$L1 = deg2rad($OrigLat);
$L2 = deg2rad($DestLat);
$I1 = deg2rad($OrigLong);
$I2 = deg2rad($DestLong);
$D = acos(cos($L1 - $L2) - (1 - cos($I1 - $I2)) * cos($L1) * cos($L2));
# One degree of such an arc on the earth's surface is 60 international nautical miles NM
return rad2deg($D * 60);
}
錯誤的,如果條件: 這是greatCircleDirection功能的,如果條件的值,需要知道什麼改變來解決它。
if (0.57700585070933 < 3.1415926535898 and 0.57700585070933 < 0) or (0.57700585070933 > 3.1415926535898 and 0.57700585070933 > 0)
例如:
from lat: 33.71,
to lat: 21,
from long: 73.06,
to long: 40 ,
distance: 1908.842544944
direction 104.96527938779 (direction should be 255.87 or so)
example added .. – Basit 2010-02-20 10:56:43