[Swlug] Re Maths calculations
Alan Gray
alan at grayhs.org
Wed Jul 20 19:06:17 UTC 2022
Hello Rhys,
Jason has done an excellent analysis of the issue.
I think, though, he is wrong in thinking that it's 'o' level stuff. They
might deal with sin, cos etc, but the analysis would be beyond most.
I also came across this on "geeksforgeeks" under "Haversine formula to
find distance between two points on a sphere"
# Python 3 program for the
# haversine formula
import math
# Python 3 program for the
# haversine formula
def haversine(lat1, lon1, lat2, lon2):
# distance between latitudes
# and longitudes
dLat = (lat2 - lat1) * math.pi / 180.0
dLon = (lon2 - lon1) * math.pi / 180.0
# convert to radians
lat1 = (lat1) * math.pi / 180.0
lat2 = (lat2) * math.pi / 180.0
# apply formulae
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 rad * c
# Driver code
if __name__ == "__main__":
lat1 = 51.5007
lon1 = 0.1246
lat2 = 40.6892
lon2 = 74.0445
print(haversine(lat1, lon1,lat2, lon2), "K.M.")
# This code is contributed
# by ChitraNayal
Kindest regards
Alan Gray
More information about the Swlug
mailing list