mirror of
https://github.com/aclist/dztui.git
synced 2026-10-31 23:22:44 +01:00
Add helper file
This commit is contained in:
1 parent
a427daabd6
commit
7b947e2996
1 file changed
+25
@@ -0,0 +1,25 @@
|
|||||||
|
import math
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def haversine(lat1, lon1, lat2, lon2):
|
||||||
|
|
||||||
|
dLat = (lat2 - lat1) * math.pi / 180.0
|
||||||
|
dLon = (lon2 - lon1) * math.pi / 180.0
|
||||||
|
|
||||||
|
lat1 = (lat1) * math.pi / 180.0
|
||||||
|
lat2 = (lat2) * math.pi / 180.0
|
||||||
|
|
||||||
|
a = (pow(math.sin(dLat / 2), 2) +
|
||||||
|
pow(math.sin(dLon / 2), 2) *
|
||||||
|
math.cos(lat1) * math.cos(lat2));
|
||||||
|
rad = 6371
|
||||||
|
c = 2 * math.asin(math.sqrt(a))
|
||||||
|
return round(rad * c)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
lat1 = float(sys.argv[1])
|
||||||
|
lon1 = float(sys.argv[2])
|
||||||
|
lat2 = float(sys.argv[3])
|
||||||
|
lon2 = float(sys.argv[4])
|
||||||
|
|
||||||
|
print(haversine(lat1, lon1, lat2, lon2))
|
||||||
Reference in new issue
Block a user