Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import radians, cos, sin, asin, sqrt
- def haversine(lat1, lon1, lat2, lon2):
- R = 6371
- dLat = (lat2 - lat1)
- dLon = (lon2 - lon1)
- lat1 = (lat1)
- lat2 = (lat2)
- a = sin(dLat/2)**2 + cos(lat1)*cos(lat2)*sin(dLon/2)**2
- c = 2*asin(sqrt(a))
- return R * c
- # Usage
- lon1, lat1 = [float(i) for i in input().split()] # 105.96 10.21
- lon2, lat2 = [float(i) for i in input().split()] # 107.17 16.79
- print("{:.2f}".format(haversine(lat1, lon1, lat2, lon2)))
- '''
- 105.96 10.21
- 107.17 16.79
- '''
Add Comment
Please, Sign In to add comment