Artificial intelligent assistant

Distance to the circumference of a circle from an inscribed point Originally my question is rooted in neutrino physics where neutrinos are produced at a height _h_ above the earth (which has radius _r_ ). Here one would like to know the distance _L_ from the source to a specific point on the earth's surface as a function of zenith angle $\phi$, _r_ and _h_. I have drawn this in the picture below to make it more comprehensible: ![distance to the circumference at a given zenith angle]( Now I have found through some research that the answer should be $L=-rcos(\phi)+\sqrt{r^2 cos^2(\phi)+h^2+2rh}$ But I cant get the trigonometry right to derive this solution.

By cosine formula, we have

$$L^2+r^2-2(L)(r)\cos(\pi-\phi)=(r+h)^2$$

Solving, we have

$$L=-r\cos\phi+\sqrt{2rh+h^2+r^2\cos^2\phi}$$

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 3737ea78ea838a82a92c5bad5335bb5c