Closest distance from point to surface is normal proof

If I have a point and a surface, the vector for the closest distance between the point and the surface will be normal to the surface:

Intuitively it makes sense. If we assume the contrary (that the closest distance vector is not normal to the surface) then we can minimize the distance by travelling in the direction that makes the distance vector normal. But how would I prove this formally? And does this theorem hold for any type of surface?

• It is normal to the tangent space only, isn't it? – user251257 Oct 2 '16 at 20:05
• @user251257 Isn't that the definition of normal? – étale-cohomology Jul 14 '17 at 3:09

If you are allowed to use Lagrange multipliers, then you're trying to find the minimum of the function $$r(X) = \|X-X_0\|$$ subject to the constraint that $g(X) = 0$, where $g$ implicitly defines the surface. The Lagrange function is $$\mathcal{L}(X) = r(X) + \lambda g(X)$$ Calculating the gradient, $$\nabla_{X,\lambda} \mathcal{L} = \left(\frac{X - X_0}{\|X - X_0\|} + \lambda \nabla\,g(X), g(X) \right)$$
Hence $$X - X_0 = -\lambda \|X - X_0\| \nabla g(X).$$ In other words, the vector $X - X_0$ is collinear to $\nabla g(X)$, which is normal to the surface.