Added angle-to-horizon and radio horizon calculations

This commit is contained in:
Mark Qvist 2023-10-25 02:57:28 +02:00
parent ecb5f0c38b
commit 9fe7632e8f

View File

@ -223,42 +223,78 @@ def orthodromic_distance(c1, c2, ellipsoid=True):
else: else:
return spherical_distance(c1, c2) return spherical_distance(c1, c2)
# def tests(): def distance_to_horizon(c, ellipsoid=False):
# import RNS if ellipsoid:
# import numpy as np raise NotImplementedError("Distance to horizon on the ellipsoid is not yet implemented")
# from geographiclib.geodesic import Geodesic else:
# geod = Geodesic.WGS84 # TODO: This is a only barely functional simplification.
# coords = [ # Need to calculate the geodesic distance to the horizon
# [(51.2308, 4.38703, 0.0), (47.699437, 9.268651, 0.0)], # instead.
# [(51.230800, 4.38703, 0.0), (51.230801, 4.38703, 0.0)], if len(c) >= 3:
# [(35.3524, 135.0302, 100), (35.3532,135.0305, 500)], r = mean_earth_radius
# [(57.758793, 22.605194, 0.0), (43.048838, -9.241343, 0.0)], h = c[2]
# [(0.0, 0.0, 0.0), (0.0, 0.0, 0.0)], return sqrt(pow((h+r),2) - r*r)
# [(-90.0, 0.0, 0.0), (90.0, 0.0, 0.0)], else:
# [(-90.0, 0.0, 0.0), (78.0, 0.0, 0.0)], return None
# [(0.0, 0.0, 0.0), (0.5, 179.5, 0.0)],
# [(0.7, 0.0, 0.0), (0.0, -180.0, 0.0)], def angle_to_horizon(c, ellipsoid=False):
# ] if ellipsoid:
# for cs in coords: raise NotImplementedError("Angle to horizon on the ellipsoid is not yet implemented")
# c1 = cs[0]; c2 = cs[1] else:
# print("Testing: "+str(c1)+" -> "+str(c2)) r = mean_earth_radius
# us = time.time() h = c[2]
# ld = c1+c2; g = geod.Inverse(c1[0], c1[1], c2[0], c2[1]) return degrees(-acos(r/(r+h)))
# print("Lib computed in "+str(round((time.time()-us)*1e6, 3))+"us")
# us = time.time() def radio_horizon(c1, c2, ellipsoid=False):
# eld = orthodromic_distance(c1,c2,ellipsoid=True) # dr = 4.12*(√h1 + √h2)
# if eld: if ellipsoid:
# print("Own computed in "+str(round((time.time()-us)*1e6, 3))+"us") raise NotImplementedError("Radio horizon on the ellipsoid is not yet implemented")
# else: else:
# print("Own timed out in "+str(round((time.time()-us)*1e6, 3))+"us") h1 = c1[2]
# ed_own = euclidian_distance(c1,c2,ellipsoid=True) h2 = c2[2]
# sd_own = orthodromic_distance(c1,c2,ellipsoid=False) ed = euclidian_distance(c1,c2)
# aa = azalt(c1,c2,ellipsoid=True) rh1 = 1e3*4.12*(sqrt(h1))
# fac = 1 rh2 = 1e3*4.12*(sqrt(h2))
# if eld: print("LibDiff = "+RNS.prettydistance(g['s12']-eld)+f" {fac*g['s12']-fac*eld}") rhc = 1e3*4.12*(sqrt(h1) + sqrt(h2))
# print("Spherical = "+RNS.prettydistance(sd_own)+f" {fac*sd_own}") return (rh1, rh2, rhc, rhc > ed)
# # print("EllipLib = "+RNS.prettydistance(g['s12'])+f" {fac*g['s12']}")
# if eld: print("Ellipsoid = "+RNS.prettydistance(eld)+f" {fac*eld}") def tests():
# print("Euclidian = "+RNS.prettydistance(ed_own)+f" {fac*ed_own}") import RNS
# print("AzAlt = "+f" {aa[0]} / {aa[1]}") import numpy as np
# print("") from geographiclib.geodesic import Geodesic
geod = Geodesic.WGS84
coords = [
[(51.2308, 4.38703, 0.0), (47.699437, 9.268651, 0.0)],
[(51.2308, 4.38703, 0.0), (47.699437, 9.268651, 30.0*1e3)],
# [(51.230800, 4.38703, 0.0), (51.230801, 4.38703, 0.0)],
# [(35.3524, 135.0302, 100), (35.3532,135.0305, 500)],
# [(57.758793, 22.605194, 0.0), (43.048838, -9.241343, 0.0)],
# [(0.0, 0.0, 0.0), (0.0, 0.0, 0.0)],
# [(-90.0, 0.0, 0.0), (90.0, 0.0, 0.0)],
# [(-90.0, 0.0, 0.0), (78.0, 0.0, 0.0)],
# [(0.0, 0.0, 0.0), (0.5, 179.5, 0.0)],
# [(0.7, 0.0, 0.0), (0.0, -180.0, 0.0)],
]
for cs in coords:
c1 = cs[0]; c2 = cs[1]
print("Testing: "+str(c1)+" -> "+str(c2))
us = time.time()
ld = c1+c2; g = geod.Inverse(c1[0], c1[1], c2[0], c2[1])
print("Lib computed in "+str(round((time.time()-us)*1e6, 3))+"us")
us = time.time()
eld = orthodromic_distance(c1,c2,ellipsoid=True)
if eld:
print("Own computed in "+str(round((time.time()-us)*1e6, 3))+"us")
else:
print("Own timed out in "+str(round((time.time()-us)*1e6, 3))+"us")
ed_own = euclidian_distance(c1,c2,ellipsoid=True)
sd_own = orthodromic_distance(c1,c2,ellipsoid=False)
aa = azalt(c1,c2,ellipsoid=True)
fac = 1
if eld: print("LibDiff = "+RNS.prettydistance(g['s12']-eld)+f" {fac*g['s12']-fac*eld}")
print("Spherical = "+RNS.prettydistance(sd_own)+f" {fac*sd_own}")
# print("EllipLib = "+RNS.prettydistance(g['s12'])+f" {fac*g['s12']}")
if eld: print("Ellipsoid = "+RNS.prettydistance(eld)+f" {fac*eld}")
print("Euclidian = "+RNS.prettydistance(ed_own)+f" {fac*ed_own}")
print("AzAlt = "+f" {aa[0]} / {aa[1]}")
print("")