Geometry: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 8: | Line 8: | ||
distance = ( ( XpointA - XpointB ) ** 2 ) + ( ( YpointA - YpointB ) ** 2 ) ** 0.5 | distance = ( ( XpointA - XpointB ) ** 2 ) + ( ( YpointA - YpointB ) ** 2 ) ** 0.5 | ||
KMonearth = distance * 100 # Very rough estimate for when using longtitude and latitude (in the Netherlands) | KMonearth = distance * 100 # Very rough estimate for when using longtitude and latitude (in the Netherlands) | ||
</syntaxhighlight> | |||
More precise should be like this I found on stackoverflow[https://stackoverflow.com/questions/19412462/getting-distance-between-two-points-based-on-latitude-longitude] | |||
<syntaxhighlight lang=python> | |||
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) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 08:29, 7 January 2025
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)