From 7b947e29960f6c50dc55a2676d938bea393ed60c Mon Sep 17 00:00:00 2001 From: aclist Date: Mon, 12 Sep 2022 19:35:50 +0900 Subject: [PATCH] Add helper file --- helpers/lat.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 helpers/lat.py diff --git a/helpers/lat.py b/helpers/lat.py new file mode 100644 index 0000000..ce2ef6d --- /dev/null +++ b/helpers/lat.py @@ -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))