Guest User

Untitled

a guest
Jul 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. function GetCenterFromDegrees(array $data)
  2. {
  3. if (!count($data)) {
  4. return false;
  5. }
  6.  
  7. $numCoords = count($data);
  8.  
  9. $X = 0.0;
  10. $Y = 0.0;
  11. $Z = 0.0;
  12.  
  13. for($i = 0; $i < count($data); $i++){
  14. $lat = $data[$i][0] * pi() / 180;
  15. $lon = $data[$i][1] * pi() / 180;
  16.  
  17. $a = cos($lat) * cos($lon);
  18. $b = cos($lat) * sin($lon);
  19. $c = sin($lat);
  20.  
  21. $X += $a;
  22. $Y += $b;
  23. $Z += $c;
  24. }
  25.  
  26. $X /= $numCoords;
  27. $Y /= $numCoords;
  28. $Z /= $numCoords;
  29.  
  30. $lon = atan2($Y, $X);
  31. $hyp = sqrt($X * $X + $Y * $Y);
  32. $lat = atan2($Z, $hyp);
  33.  
  34. $newX = ($lat * 180 / pi());
  35. $newY = ($lon * 180 / pi());
  36.  
  37. return [$newX, $newY];
  38. }
Add Comment
Please, Sign In to add comment