metric.py 399 B

123456789101112131415
  1. from math import pi, asin, cos, sin, sqrt
  2. def spherical_distance(a, b):
  3. coef = pi / 180
  4. radlat1 = a[1] * coef
  5. radlat2 = b[1] * coef
  6. radlng1 = a[0] * coef
  7. radlng2 = b[0] * coef
  8. a = sin((radlat1 - radlat2)/2)**2
  9. b = cos(radlat1) * cos(radlat2) * sin((radlng1 - radlng2)/2) ** 2
  10. return asin(sqrt(a+b))
  11. def ang_distance(a, b):
  12. x = abs(a-b)
  13. return min(x, 360-x)