Skip to content

Instantly share code, notes, and snippets.

@tomtana
Last active April 2, 2024 22:15
Show Gist options
  • Save tomtana/f8d360f494cbf74072dbd5ae78166df8 to your computer and use it in GitHub Desktop.
Save tomtana/f8d360f494cbf74072dbd5ae78166df8 to your computer and use it in GitHub Desktop.
Compute theoretical maximal visibility on earth with the assumption of the earth being a perfect sphere
"""Compute theoretical maximal visibility on earth with the assumption of the earth being a perfect sphere and the absence of refraction.
Some interesting links:
https://aty.sdsu.edu/explain/atmos_refr/horizon.html
https://sites.math.washington.edu/~conroy/m120-general/horizon.pdf
"""
import numpy as np
RADIAN_EARTH = 6371e3 # meters
def compute_direct_distance(h_obs, h_obj, r=RADIAN_EARTH):
"""
Compute maximum distance an observer with height h1 can see an object with height h2.
The distance is direct (straight line) between h1 and h2.
Pythagoras can be used here since at maximal possible distance, the line connecting h1 and h2
will be tangential to min(h1,h2) forming a right triangle.
:param h_obs: observation height in m
:param h_obj: object height in m
:param r: radian of earth in m
:return: distance of line connecting top of h1 and h2 in km
"""
hypotenuse = max(h_obs, h_obj) + r
adjacent = min(h_obs, h_obj) + r
return np.sqrt(hypotenuse**2 - adjacent**2) * 1e-3
def get_angle(h_obs, h_obj, r=RADIAN_EARTH):
"""
Compute angle between h1+r and h2+r at maximum distance an observer with height h1
can see an object with height h2.
:param h_obs: observation height in m
:param h_obj: object height in m
:param r: radian of earth in m
:return: distance of line connecting top of h1 and h2 in km
"""
d_direct = compute_direct_distance(h_obs, h_obj, r)
hypotenuse = max(h_obs, h_obj) + r
return np.arctan2(d_direct, hypotenuse)
def compute_surface_distance(h_obs, h_obj, r=RADIAN_EARTH):
"""
Compute maximum distance an observer with height h1 can see an object with height h2.
The computed distance is the distance over the earth surface
Pythagoras can be used here since at maximal possible distance, the line connecting h1 and h2
will be tangential to min(h1,h2) forming a right triangle.
:param h_obs: observation height in m
:param h_obj: object height in m
:param r: radian of earth in m
:return: distance on earth surface between h1 and h2 in km
"""
return r * get_angle(h_obs, h_obj, r)
if __name__ == "__main__":
for i in range(1,200):
h_obs = 2 # m
h_obj = 1 * i # m
print(f"""
Max visibility with an eyes on height {h_obs}[m] and object of height {h_obj}[m]
direct distance: {compute_direct_distance(h_obs, h_obj)}[km]
surface distance: {compute_surface_distance(h_obs, h_obj)}[km]
angle rad: {get_angle(h_obs, h_obj)}[rad]
angle deg: {np.rad2deg(get_angle(h_obs, h_obj))}[deg]
""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment