Created
October 25, 2018 10:30
-
-
Save kdes70/36cd197956d928e6a68716449882ae36 to your computer and use it in GitHub Desktop.
Вычислить дистанцию
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function calculate_distance($cord1, $cord2){ | |
$rad = 6372795; | |
$lat1 = (float)$cord1[0]*M_PI/180; | |
$long1 = (float)$cord1[1]*M_PI/180; | |
$lat2 = (float)$cord2[0]*M_PI/180; | |
$long2 = (float)$cord2[1]*M_PI/180; | |
// косинусы и синусы широт и разницы долгот | |
$cl1 = cos($lat1); | |
$cl2 = cos($lat2); | |
$sl1 = sin($lat1); | |
$sl2 = sin($lat2); | |
$delta = $long2 - $long1; | |
$cdelta = cos($delta); | |
$sdelta = sin($delta); | |
// вычисления длины большого круга | |
$y = sqrt(pow($cl2 * $sdelta, 2) + pow($cl1 * $sl2 - $sl1 * $cl2 * $cdelta, 2)); | |
$x = $sl1 * $sl2 + $cl1 * $cl2 * $cdelta; | |
// | |
$ad = atan2($y, $x); | |
$dist = $ad * $rad; | |
return $dist; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment