TITLE: Minimum distance between point and face
QUESTION [8 upvotes]: Given a point in 3D space of the form (x, y, z) and a triangle consisting of 3 vectors (also in the (x, y, z) format), how would I calculate the minimum distance between the point and the face of the triangle?
I understand it involves the normal of the plane that the triangle lies on however I'm unsure how to calculate the plane and then the magnitude of the plane's normal, to the point.
Thanks for any help!

REPLY [2 votes]: Jordi Cruzado's edit breaks down when dealing with obtuse triangles. This answer builds on Jordi Cruzado's answer to allow it to be applied to obtuse triangles. References to "the figure" refer to this figure.

The Problem
In Jordi Cruzado's approach, the region of the plane outside the triangle is broken into six sections. See the top panel of the figure. In these regions, $\alpha$, $\beta$, and $\gamma$ obey the following inequalities, which can be used to test which region $p_0$ is in:

I: $\alpha \geq 0$, $\beta \geq 0$, $\gamma < 0$
II: $\alpha < 0$, $\beta \geq 0$, $\gamma < 0$
III: $\alpha < 0$, $\beta \geq 0$, $\gamma \geq 0$
IV: $\alpha < 0$, $\beta < 0$, $\gamma \geq 0$
V: $\alpha \geq 0$, $\beta < 0$, $\gamma \geq 0$
VI: $\alpha \geq 0$, $\beta < 0$, $\gamma < 0$

According to Jordi Cruzado's edit, when $p_0$ is in regions I, III, and V, it is closest to the edge formed by $v_1$ and $v_2$, $v_2$ and $v_3$, and $v_1$ and $v_3$, respectively. When $p_0$ is in regions II, IV, and VI, it is closest to $v_2$, $v_3$, and $v_1$, respectively.
In the top panel of the figure, gray boxes represent the regions of the plane that are actually closest to the edges of the triangle. Two of each box's edges are rays perpendicular to the triangle's edges starting at the triangle's vertices. Using these boxes, you can see that portions of region II are actually closer to edges of the triangle than they are to $v_2$.

The Solution
To avoid this error, you can bisect regions II, IV, and VI. See the bottom panel of the figure. To determine which subregion $p_0$ is in, you can use the following inequalities, which also tell you which edge is closest to $p_0$:

IIa: $\gamma \leq \alpha$ - Edge $v_1$, $v_2$
IIb: $\gamma \geq \alpha$ - Edge $v_2$, $v_3$
IVa: $\alpha \leq \beta$ - Edge $v_2$, $v_3$
IVb: $\alpha \geq \beta$ - Edge $v_1$, $v_3$
VIa: $\beta \leq \gamma$ - Edge $v_1$, $v_3$
VIb: $\beta \geq \gamma$ - Edge $v_1$, $v_2$

Once you have determined which edge $p_0$ is closest to, you can determine which point within the triangle edge $p$ is closest to, and you can calculate the distance from this point to $p$, as in Jordi Cruzado's original answer. 
I'm sure there are more elegant solutions to this problem, but this approach will work.