Skip to content

Instantly share code, notes, and snippets.

@recheej
Created July 2, 2015 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recheej/2cd26772d54b321f10f4 to your computer and use it in GitHub Desktop.
Save recheej/2cd26772d54b321f10f4 to your computer and use it in GitHub Desktop.
__author__ = 'reche_000'
import math
class Point:
def __init__(self, lat=0.0, long=0.0):
self.latitude = lat
self.longitude = long
def haversin_dinstance(pointOne, pointTwo):
sin_one = math.sin((pointTwo.latitude - pointOne.latitude) / 2)
sin_one *= sin_one
sin_two = math.sin((pointTwo.longitude - pointOne.longitude) / 2)
sin_two *= sin_two
under_square = sin_one + (math.cos(pointOne.latitude) * math.cos(pointTwo.latitude) * sin_two)
earth_radius = 6371
return 2 * earth_radius * math.asin(math.sqrt(under_square))
def detour_distance(pointA, pointB, pointC, pointD):
driver_one_detour = haversin_dinstance(pointA, pointC) + haversin_dinstance(pointC, pointD)
driver_two_detour = haversin_dinstance(pointC, pointA) + haversin_dinstance(pointA, pointB)
return min(driver_one_detour, driver_two_detour)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment