0

出発(緯度、経度)と到着(緯度、経度)があります。計算後、コンパスを使用して移動するための最も近い方法が表示されるはずです。以下はそれを行うための 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);
    }

if 条件のバグ: これは、greatCircleDirection 関数の if 条件の値です。修正するには、何を変更すればよいかを知る必要があります。

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)
4

3 に答える 3

1

さて、あなたの距離計算はチェックアウトします。しかし、最初の方位に対して得られる答えは、(0-105)mod360 (およそ) ではなく (0+105)mod360 であるため、GreatCircleDirection 関数の if ステートメントのどこかに間違った符号があると思われます。

于 2010-02-20T11:34:11.493 に答える
1

距離の計算は不要です。単に操作が増えるだけで、数値エラーが増える可能性があります。コーディングのスタイルを使用すると、次のようなものが機能するはずです。

function GreatCircleDirection($OrigLat, $OrigLong, $DestLat, $DestLong)
{   
   $L1 = deg2rad($OrigLat);
   $I1 = deg2rad($OrigLong);
   $L2 = deg2rad($DestLat);
   $I2 = deg2rad($DestLong);
   return rad2deg(atan2((sin($I2-$I1),cos($L1)*tan($L2)-sin($L1)*cos($I2-$I1)));
}

atan2 関数は、方向の正しい象限を識別し、真北から測定した -180 ~ 180 度の角度を提供します。たとえば、GreaterCircleDirection(39,-77,21,40) は 56.76 度と評価されます。使用される符号規則: 緯度は、北が正、南が負です。経度は東がプラス、西がマイナスです。

計算については、http://patriot.net/~abdali/ftp/qibla.pdfなどで説明されています。

于 2010-02-21T05:49:27.087 に答える
0

おそらく、http: //www.krysstal.com/sphertrig.html の「Using the Sine Rule」の下にある実際の例が役立つでしょう。

于 2010-02-20T10:01:30.047 に答える