The formula laid out doesn't caluclate distance well, as line of sight is not the measure of distance across a globe. instead I would make the assumption that the distance is an arc segment. This has the added benefit that when d_surface_0 < d_surface_1, the heigh for an obscuring object is calculated.
Example python code
from math import pi,inf,acos,cos
R=6371*1000
h_1 = 2
d_surf_0 = R*pi
theta_1 = acos(R/(h_1+R))
d_surf_1 = R*theta_1
print("horizon: %.02f" % d_surf_1)
d_surf_2 = d_surf_0 - d_surf_1
theta_2 = d_surf_2/R
if theta_2 > pi/2:
h_2 = inf
else:
h_2 = R/cos(theta_2)-R
print("height: %.02f" % h_2)
The formula laid out doesn't caluclate distance well, as line of sight is not the measure of distance across a globe. instead I would make the assumption that the distance is an arc segment. This has the added benefit that when d_surface_0 < d_surface_1, the heigh for an obscuring object is calculated.
Example python code