bearing
This commit is contained in:
38
minimap.py
38
minimap.py
@ -104,6 +104,34 @@ def haversine(coord1, coord2):
|
|||||||
|
|
||||||
return c * r
|
return c * r
|
||||||
|
|
||||||
|
def haver_dist(coord1, coord2):
|
||||||
|
lati1 = math.radians(coord1[0])
|
||||||
|
long1 = math.radians(coord1[1])
|
||||||
|
lati2 = math.radians(coord2[0])
|
||||||
|
long2 = math.radians(coord2[1])
|
||||||
|
dlong = long2 - long1
|
||||||
|
dlati = lati2 - lati1
|
||||||
|
a = (
|
||||||
|
math.sin(dlati / 2) ** 2
|
||||||
|
+ math.cos(lati1) * math.cos(lati2) * math.sin(dlon / 2) ** 2
|
||||||
|
)
|
||||||
|
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
|
||||||
|
distance = R * c
|
||||||
|
return distance*1000
|
||||||
|
|
||||||
|
def bearing(coord1, coord2):
|
||||||
|
lati1 = math.radians(coord1[0])
|
||||||
|
long1 = math.radians(coord1[1])
|
||||||
|
lati2 = math.radians(coord2[0])
|
||||||
|
long2 = math.radians(coord2[1])
|
||||||
|
y = math.sin(long2 - long1) * math.cos(lati2)
|
||||||
|
x = math.cos(lati1) * math.sin(lati2) - math.sin(lati1) * math.cos(
|
||||||
|
lati2
|
||||||
|
) * math.cos(long2 - long1)
|
||||||
|
intbearing = math.atan2(y, x)
|
||||||
|
intbearing = math.degrees(intbearing)
|
||||||
|
intbearing = (intbearing + 360) % 360
|
||||||
|
return intbearing
|
||||||
|
|
||||||
def update_display():
|
def update_display():
|
||||||
display.fill(0)
|
display.fill(0)
|
||||||
@ -118,11 +146,13 @@ def update_display():
|
|||||||
d = location_avg()
|
d = 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:
|
||||||
distance = haversine(d, (val[0][0],val[0][1]))
|
d = haver_dist(d, (val[0][0],val[0][1]))
|
||||||
|
b = bearing(d, (val[0][0],val[0][1]))
|
||||||
else:
|
else:
|
||||||
distance = float('inf')
|
d = float('inf')
|
||||||
print(name, "is", distance)
|
b = float('NaN')
|
||||||
display.text(f"{name}: {distance}", 0, 10*(i+1), 1)
|
print(name, ":", d, b)
|
||||||
|
display.text(f"{name}: {d} {b}", 0, 10*(i+1), 1)
|
||||||
display.show()
|
display.show()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user