Найти радиус круга от северо-востока-юго-востока.Php

Кемеровские программисты php общаются здесь
Anonymous
Найти радиус круга от северо-востока-юго-востока.

Сообщение Anonymous »

Мне удалось найти функцию, которая давала мне координаты северо-восточного и юго-западного углов по заданной широте и радиусу.

Код: Выделить всё

/**
* 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...

Подробнее здесь: https://stackoverflow.com/questions/331 ... ne-sw-area

Вернуться в «Php»