Geometry: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| 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 (https://en.wikipedia.org/wiki/Earth_radius) | |||
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> | ||
Revision as of 09:59, 26 November 2024
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 (https://en.wikipedia.org/wiki/Earth_radius)
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)