# Distance between cone and point

How can I find minimum distance between cone and a point ?

Cone properties :
position - $(0,0,z)$
radius - $R$
height - $h$

Point properties:
position - $(0,0,z_1)$

-
Are you only interested in the given trivial case or one for any point? – Karolis Juodelė Nov 25 '12 at 12:42
@KarolisJuodelė any point – jques Nov 25 '12 at 12:57

Put all shapes into a cylindrical coordinate system $(\phi, r, h)$, such that the axis of the cone satisfies $r = 0$. Now, by symmetry of cone, you can throw away $\phi$ and work in two dimensions.
You now have an isosceles triangle with point $A$ at the top and $B$ on the bottom, closer to the given point $X$. Now, the distance is given by $$\begin{cases}0 & X_h \geq B_h \wedge \vec{X}\cdot \vec{n} < \vec{A} \cdot \vec{n} \\B_h - X_h& X_h < B_h \wedge X_r < B_r \\AX^2-\Big(\frac{\vec{AX}\cdot\vec{AB}}{AB} \Big)^2 & \vec{AX}\cdot\vec{AB} \geq 0 \wedge \vec{BX}\cdot\vec{BA} \geq 0 \\ \min \{AX, BX\}& otherwise\end{cases}$$
Here $X_h, X_r$ indicate the two coordinates of $X$, $\cdot$ is the inner product and $\vec{n}$ is a normal of $AB$ pointing outwards.