This commit is contained in:
cqc
2026-01-04 11:21:06 +01:00
parent 374622d5d0
commit d5f61cb64d

View File

@ -76,34 +76,6 @@ def update_location():
import math import math
def haversine(coord1, coord2):
"""
Calculate the great-circle distance between two points on the Earth
specified in decimal degrees (latitude and longitude).
Parameters:
coord1 (tuple): (latitude, longitude) for point 1
coord2 (tuple): (latitude, longitude) for point 2
Returns:
float: distance in kilometers between the two points
"""
# Convert latitude and longitude from degrees to radians
lat1, lon1 = map(math.radians, coord1)
lat2, lon2 = map(math.radians, coord2)
# Haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = math.sin(dlat / 2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2)**2
c = 2 * math.asin(math.sqrt(a))
# Radius of Earth in kilometers (mean radius)
r = 6371.0
return c * r
def haver_dist(coord1, coord2): def haver_dist(coord1, coord2):
lati1 = math.radians(coord1[0]) lati1 = math.radians(coord1[0])
long1 = math.radians(coord1[1]) long1 = math.radians(coord1[1])
@ -143,11 +115,11 @@ def update_display():
print(l) print(l)
d = location_avg() lavg = location_avg()
for (name,val), i in zip(l['points'].items(), range(len(l['points']))): for (name,val), i in zip(l['points'].items(), range(len(l['points']))):
if len(val) > 0: if len(val) > 0:
d = haver_dist(d, (val[0][0],val[0][1])) d = haver_dist(lavg, (val[0][0],val[0][1]))
b = bearing(d, (val[0][0],val[0][1])) b = bearing(lavg, (val[0][0],val[0][1]))
else: else:
d = float('inf') d = float('inf')
b = float('NaN') b = float('NaN')