I wonder if there exists a good enough formula to compute the shortest distance between a point $P=(x_0,y_0,z_0)$ and a surface $\pi$ defined by $F(x,y,z)=0$. There is a lot of simmilar questions in this site but any of those concern a general surface.
In particular, if we assume that the 'shortest' vector from $Q$ to $\pi$ is always normal to $\pi$ then, if $Q=(a,b,c)$ is the closest point in $\pi$ to $P$, there exists a real number $\alpha$ such that $$P-Q=\alpha\left(\vec\nabla F(Q)-Q\right)$$ where $\vec\nabla F(Q)$ is $\left<\frac{\partial F}{\partial x},\frac{\partial F}{\partial y},\frac{\partial F}{\partial z}\right>$ at point $Q$. Then if our main assumption is correct, the distance is $\|P-Q\|$, but we still have to compute $\alpha$. This is maybe not the correct way to proceed, so i would appreciate some hints. Thanks in advance.
The problem is a little simpler when you know some parametric equation of the surface,
$$Q=Q(u,v),\text{ with }(u,v)\in D$$ for some domain $D$.
You need to minimize $\overline{PQ}^2$, which by differentiation yields the system
$$(Q(u,v)-P)\cdot\frac{\partial Q(u,v)}{\partial u}=0,\\ (Q(u,v)-P)\cdot\frac{\partial Q(u,v)}{\partial v}=0.$$
This is still nonlinear, but the complexity dropped to two equations in two unknowns.
A simple example:
Let us consider a sphere of radius one at the origin. In spherical coordinates, with an (hopefully) obvious notation $$Q=(c_u s_v, s_u s_v, c_v),$$ and a point on the $z$ axis $$P=(0,0,p).$$
The minimization equations are $$(c_u s_v)(-s_u s_v) + (s_u s_v)(c_u s_v) + (c_v - p) (0) = 0,\\ (c_u s_v)(c_u c_v) + (s_u s_v)(s_u c_v) + (c_v - p) (-s_v) = 0. $$ and simplify as $$0=0,\\s_vp=0.$$
Then $s_v=0,c_v=\pm1$, $u$ can take any value and $$Q_{min}=(0,0,\pm1)$$ where the sign is taken to get the closest point from $P$.
$$d=\min(|p-1|,|p+1|).$$
Note that the case of $p=0$ is singular, as $s_v$ can take any value and $P$ is equidistant to the whole surface.