【问题标题】:Find circle radius from NE SW area从 NE SW 区域查找圆半径
【发布时间】:2015-10-13 15:46:34
【问题描述】:

我设法找到了一个函数,它给我 NE 角和 SW 角坐标,给定一个 latLng 和一个半径。

/**
 * Get NE & SW coordinates around a point
 * 
 * @param $lat float latitude of origin pt
 * @param $lng float longitude of origin pt
 * @param $distance int radius in km
 * 
 */
function getBoundsCoords($latitude, $longitude, $distance) {
    $radius = 6378.1;

    $neLat = rad2deg(asin(sin(deg2rad($latitude)) * cos($distance / $radius) + cos(deg2rad($latitude)) * sin($distance / $radius) * cos(deg2rad(0))));
    $swLat = rad2deg(asin(sin(deg2rad($latitude)) * cos($distance / $radius) + cos(deg2rad($latitude)) * sin($distance / $radius) * cos(deg2rad(180))));
    $neLng = rad2deg(deg2rad($longitude) + atan2(sin(deg2rad(90)) * sin($distance / $radius) * cos(deg2rad($latitude)), cos($distance / $radius) - sin(deg2rad($latitude)) * sin(deg2rad($neLat))));
    $swLng = rad2deg(deg2rad($longitude) + atan2(sin(deg2rad(270)) * sin($distance / $radius) * cos(deg2rad($latitude)), cos($distance / $radius) - sin(deg2rad($latitude)) * sin(deg2rad($neLat))));

    return array(
        'ne' => array(
            'lat' => $neLat,
            'lng' => $neLng
        ),
        'sw' => array(
            'lat' => $swLat,
            'lng' => $swLng
        )
    );
}

我还设法找到了对面函数的一部分,它给我返回了中心点坐标(很容易),但我无法找到返回的半径:

function getCoordsFromBounds($coordsNeSw) {
    return array(
        'lat' => ($coordsNeSw['ne']['lat'] + $coordsNeSw['sw']['lat']) / 2,    
        'lng' => ($coordsNeSw['ne']['lng'] + $coordsNeSw['sw']['lng']) / 2,
        'radius' => "??????"
    );
}

我怀疑我应该做与 getBoundsCoords() 函数相反的操作,但我对 sin/cos/deg/rad 不太满意...

【问题讨论】:

  • 当您说“来自 NE SW 区域”时,您的意思是您获得了平方英里,或者您获得了 NE 和 SW 坐标并且您需要基于此的半径?
  • NE 和 SW 坐标已给出,我正在根据该坐标寻找半径

标签: php geometry coordinates


【解决方案1】:

假设您的 getCoordsFromBounds 仅适用于正方形,而不适用于矩形,则半径将是两个纬度或经度之间距离的一半。纬度差比经度更容易计算。基于纬度的距离几乎恒定在 111 公里/度(极地到赤道略有不同)

所以你的正方形顶部和底部之间的距离是(以公里为单位)

$distance = abs(($coordsNeSw['ne']['lat'] - $coordsNeSw['sw']['lat'])) * 111

因此半径是一半

$radius = $distance / 2

我认为您计算边界框的解决方案似乎比需要的复杂,请参阅Calculating bounding box a certain distance away from a lat/long coordinate in Java

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-27
    • 2012-03-16
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多