Distance From Eye or Foot to Horizon of a Sphere PHP Program by Jay Tanner  
This program computes the lineofsight distance and the curved surface distance to the horizon of a sphere at any distance of the eye as reckoned from the surface or center of the sphere. The radius and distance can be in any convenient linear units.
The initial default radius is the mean lunar radius and the distance is a random distance value from 1 to 500 miles above the surface of the moon. LineofSight Distance (H) to Horizon = 889.03672590057 units Surface Distance (S) to Horizon = 743.68602380321 unitsDistance (d) to the eye is reckoned from the surface of the sphere. This corresponds to the minimum radar distance to the nearest surface point. Where the Distance to the Eye Is Reckoned From the Center of the Sphere:
Given the radius ( R ) of the sphere and the distance (D ) of the eye from the center of the sphere, the general equation for the lineofsight distance (H ) to the sphere horizon viewed from that point is:
The horizon surface distance (S) , corresponding to (H) , but measured along the curved surface of the sphere directly below H and corresponding to the sailing distance is:
Where: D > R and R > 0 and the inverse angle is expressed in radians
Where the Distance to the Eye Is Reckoned From the Surface of the Sphere:
Given the radius
(R) of the sphere and the distance (d) (H) to the sphere horizon viewed from that point is:
The horizon surface distance (S) , corresponding to lineofsight distance (H) , but measured along the curved surface of the sphere, corresponding to the sailing distance is:
Where: R > 0 and d > 0 and the inverse angle is expressed in radians
