문제

나는 두 지점 사이의 대권 거리를 계산하는 공식을 잘 알고 있습니다.

즉.

<?php
$theta = $lon1 - $lon2; 
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
$dist = acos($dist); 
$dist = rad2deg($dist); 
//convert degrees to distance depending on units desired
?>

하지만 내가 필요한 것은 이것의 반대입니다.시작점, 거리 및 간단한 기본 NSEW 방향이 주어지면 대상 지점의 위치를 ​​계산합니다.오랜만에 수학 수업을 들었습니다.;)

도움이 되었습니까?

해결책

내가 찾은 C 구현은 다음과 같습니다. PHP로 변환하는 것이 매우 간단합니다.

#define KmPerDegree         111.12000071117
#define DegreesPerKm        (1.0/KmPerDegree)
#define PI                  M_PI
#define TwoPI               (M_PI+M_PI)
#define HalfPI              M_PI_2
#define RadiansPerDegree    (PI/180.0)
#define DegreesPerRadian    (180.0/PI)
#define copysign(x,y)       (((y)<0.0)?-fabs(x):fabs(x))
#define NGT1(x)             (fabs(x)>1.0?copysign(1.0,x):(x))
#define ArcCos(x)           (fabs(x)>1?quiet_nan():acos(x))
#define hav(x)              ((1.0-cos(x))*0.5)              /* haversine */
#define ahav(x)             (ArcCos(NGT1(1.0-((x)*2.0))))   /* arc haversine */
#define sec(x)              (1.0/cos(x))                    /* secant */
#define csc(x)              (1.0/sin(x))                    /* cosecant */

/*
**  GreatCirclePos() --
**
**  Compute ending position from course and great-circle distance.
**
**  Given a starting latitude (decimal), the initial great-circle
**  course and a distance along the course track, compute the ending
**  position (decimal latitude and longitude).
**  This is the inverse function to GreatCircleDist).
*/
void
GreatCirclePos(dist, course, slt, slg, xlt, xlg)
    double  dist;   /* -> great-circle distance (km) */
    double  course; /* -> initial great-circle course (degrees) */
    double  slt;    /* -> starting decimal latitude (-S) */
    double  slg;    /* -> starting decimal longitude(-W) */
    double  *xlt;   /* <- ending decimal latitude (-S) */
    double  *xlg;   /* <- ending decimal longitude(-W) */
{
    double  c, d, dLo, L1, L2, coL1, coL2, l;

    if (dist > KmPerDegree*180.0) {
        course -= 180.0;
        if (course < 0.0) course += 360.0;
        dist    = KmPerDegree*360.0-dist;
    }
    if (course > 180.0) course -= 360.0;
    c    = course*RadiansPerDegree;
    d    = dist*DegreesPerKm*RadiansPerDegree;
    L1   = slt*RadiansPerDegree;
    slg *= RadiansPerDegree;
    coL1 = (90.0-slt)*RadiansPerDegree;
    coL2 = ahav(hav(c)/(sec(L1)*csc(d))+hav(d-coL1));
    L2   = HalfPI-coL2;
    l    = L2-L1;
    if ((dLo=(cos(L1)*cos(L2))) != 0.0)
        dLo  = ahav((hav(d)-hav(l))/dLo);
    if (c < 0.0) dLo = -dLo;
    slg += dLo;
    if (slg < -PI)
        slg += TwoPI;
    else if (slg > PI)
        slg -= TwoPI;

    *xlt = L2*DegreesPerRadian;
    *xlg = slg*DegreesPerRadian;

} /* GreatCirclePos() */

원천: http://sam.ucsd.edu/sio210/propseawater/ppsw_c/gcdist.c

다른 팁

내 질문에 답하기 위해 Chad Birch가 제공한 C 함수에서 변환된 PHP 클래스를 소개합니다.

class GreatCircle 
{

    /*
     * Find a point a certain distance and vector away from an initial point
     * converted from c function found at: http://sam.ucsd.edu/sio210/propseawater/ppsw_c/gcdist.c
     * 
     * @param int distance in meters
     * @param double direction in degrees i.e. 0 = North, 90 = East, etc.
     * @param double lon starting longitude
     * @param double lat starting latitude
     * @return array ('lon' => $lon, 'lat' => $lat)
     */
    public static function getPositionByDistance($distance, $direction, $lon, $lat)
    {
        $metersPerDegree = 111120.00071117;
        $degreesPerMeter = 1.0 / $metersPerDegree;
        $radiansPerDegree = pi() / 180.0;
        $degreesPerRadian = 180.0 / pi();

        if ($distance > $metersPerDegree*180)
        {
            $direction -= 180.0;
            if ($direction < 0.0)
            {
                $direction += 360.0;
            }
            $distance = $metersPerDegree * 360.0 - $distance;
        }

        if ($direction > 180.0)
        {
            $direction -= 360.0;
        }

        $c = $direction * $radiansPerDegree;
        $d = $distance * $degreesPerMeter * $radiansPerDegree;
        $L1 = $lat * $radiansPerDegree;
        $lon *= $radiansPerDegree;
        $coL1 = (90.0 - $lat) * $radiansPerDegree;
        $coL2 = self::ahav(self::hav($c) / (self::sec($L1) * self::csc($d)) + self::hav($d - $coL1));
        $L2   = (pi() / 2) - $coL2;
        $l    = $L2 - $L1;

        $dLo = (cos($L1) * cos($L2));
        if ($dLo != 0.0)
        {
            $dLo  = self::ahav((self::hav($d) - self::hav($l)) / $dLo);
        }

        if ($c < 0.0) 
        {
            $dLo = -$dLo;
        }

        $lon += $dLo;
        if ($lon < -pi())
        {
            $lon += 2 * pi();
        }
        elseif ($lon > pi())
        {
            $lon -= 2 * pi();
        }

        $xlat = $L2 * $degreesPerRadian;
        $xlon = $lon * $degreesPerRadian;

        return array('lon' => $xlon, 'lat' => $xlat);
    }


    /*
     * copy the sign
     */
    private static function copysign($x, $y)
    {
        return ((($y) < 0.0) ? - abs($x) : abs($x));
    }   

    /*
     * not greater than 1
     */
    private static function ngt1($x)
    {
        return (abs($x) > 1.0 ? self::copysign(1.0 , $x) : ($x));
    }   

    /*
     * haversine
     */
    private static function hav($x)
    {
        return ((1.0 - cos($x)) * 0.5);
    }

    /*
     * arc haversine
     */
    private static function ahav($x)
    {
        return acos(self::ngt1(1.0 - ($x * 2.0)));
    }

    /*
     * secant
     */
    private static function sec($x)
    {
        return (1.0 / cos($x));
    }

    /*
     * cosecant
     */
    private static function csc($x)
    {
        return (1.0 / sin($x));
    }

}

Haversine 공식을 철회한 다음 직접 생성하는 것이 더 어려울 것이라고 생각합니다.

먼저 표면의 "직선"을 이동하여 지구 코어에서 생성된 각도입니다(직선이라고 생각하지만 곡선입니다).

라디안 각도 = 호 길이 / 반경.각도 = ArcLen/6371km

위도는 각도의 "수직"(북쪽/남쪽) 구성 요소이므로 쉬워야 합니다.

Lat1 + Cos(베어링) * 각도

경도 구분은 위도에 따라 다릅니다.그래서 더 어려워집니다.다음을 사용합니다:

Sin(방위) * 각도(동쪽을 음수로 정의)를 사용하여 경도 방향의 각도를 구하지만 해당 위도에서 실제 경도로 다시 변환하는 것이 더 어렵습니다.

섹션을 참조하세요 시작점으로부터의 거리와 방위가 지정된 목적지점 이 웹사이트에서: http://www.movable-type.co.uk/scripts/latlong.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top