Geometry
Jump to navigation
Jump to search
XpointA = 1
YpointA = 1
XpointB = 2
YpointB = 2
distance = ( ( XpointA - XpointB ) ** 2 ) + ( ( YpointA - YpointB ) ** 2 ) ** 0.5
KMonearth = distance * 100 # Very rough estimate for when using longtitude and latitude (in the Netherlands)
More precise should be like this I found on stackoverflow[1]
from math import sin, cos, sqrt, atan2, radians
''' Approximate radius of earth in km from https://en.wikipedia.org/wiki/Earth_radius
Approximate radius of earth in km for the middle of the netherlands
See https://nl.wikipedia.org/wiki/Geografisch_middelpunt_van_Nederland.
Location Oosteinde (52° 44′ 52″ NB, 6° 17′ 48″ OL,
Radius according https://planetcalc.com/7721/ '''
R = 6371.0
lat1 = radians(Alat)
lon1 = radians(Alon)
lat2 = radians(Blat)
lon2 = radians(Blon)
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
c = 2 * atan2(sqrt(a), sqrt(1 - a))
distance = R * c
print("Result: ", distance)