This is the explicit equation to determine the distance of any point on, below, or above the surface of the Earth to the center of the Earth.
This equation uses the WGS 84 ellipsoid as it is the most current for defining the oblate spheroid shape of the Earth. This ellipsoid defines nominal (mean) sea level for the world by way of the two ellipse parameters a and b, the semimajor and semiminor axes respectively.
The Equation
D = f(Φ,Z,G) = {(a4cos2Φ+ b4sin2Φ)/(a2cos2Φ + b2sin2Φ) + 2(Z + G)(a2cos2Φ + b2sin2Φ)½ + (Z + G)2}½
or, in a different HTML format...
(if this doesn't show square root symbols, try another browser or just use the equation above)