Created
July 2, 2015 01:00
-
-
Save recheej/2cd26772d54b321f10f4 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
__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