import math
from math import cos, asin, sqrt


def distance(origin, destination):
	lat1, lon1 = origin
	lat2, lon2 = destination

	p = 0.017453292519943295     # Pi/180
	a = 0.5 - cos((lat2 - lat1) * p) / 2 + cos(lat1 * p) * cos(lat2 * p) * (1 - cos((lon2 - lon1) * p)) / 2
	return 12742 * asin(sqrt(a))  # 2*R*asin...


def distance_arc(origin, destination):
	lat1, lon1 = origin
	lat2, lon2 = destination

	# phi = 90 - latitude
	degrees_to_radians = 0.017453292519943295     # Pi/180

	phi1 = (90.0 - lat1) * degrees_to_radians
	phi2 = (90.0 - lat2) * degrees_to_radians

	# theta = longitude
	theta1 = lon1 * degrees_to_radians
	theta2 = lon2 * degrees_to_radians

	# Compute spherical distance from spherical coordinates.

	# For two locations in spherical coordinates
	# (1, theta, phi) and (1, theta, phi)
	# cosine( arc length ) =
	#    sin phi sin phi' cos(theta-theta') + cos phi cos phi'
	# distance = rho * arc length

	cos = (math.sin(phi1) * math.sin(phi2) * math.cos(theta1 - theta2) + math.cos(phi1) * math.cos(phi2))
	arc = math.acos(cos)

	return 6371 * arc
