What is the in-plane distance from a 3D point to a 3D triangle? I have a 3D point P and a triangle represented by three 3D vertices, v0, v1, and v2. I also have a normal vector for a plane, N. The point P is on this plane.
How do I find the distance along the plane from the point to the triangle?
For example, I want the length of the green line, not the red line:

In my use-case, the plane will always be axis-aligned. Does that make the formula more simple? Also assume that we already know that the plane does intersect the triangle.
 A: As z100 comments, the closest distance measured in the plane is either the distance to one of the intersections $\mathbf Q_1$ and $\mathbf Q_2$ of the triangle’s sides with the plane, or the distance to the line through those two points. The latter is measured perpendicularly to the line, so it is the distance to the intersection $\mathbf R$ of the line with its perpendicular plane through $\mathbf P$. This will be the shortest distance when $\mathbf R$ lies between $\mathbf Q_1$ and $\mathbf Q_2$.  
All of these points are easily computed via what is essentially linear interpolation. If $\mathbf N$ is the normal to a plane through the origin and $\mathbf P$ an arbitrary point, then $\mathbf N\cdot\mathbf P$ is proportional to the distance between $\mathbf P$ and the plane, and its sign indicates on which side of the plane it lies relative to the direction of $\mathbf N$. By exploiting similar triangles, we can find a formula for the intersection of a plane through the origin with normal $\mathbf N$ with the line through points $\mathbf P_1$ and $\mathbf P_2$: $${(\mathbf P_1\cdot\mathbf N)\mathbf P_2-(\mathbf P_2\cdot\mathbf N)\mathbf P_1 \over (\mathbf P_1\cdot\mathbf N)-(\mathbf P_2\cdot\mathbf N)}.\tag1$$ One can develop a similar formula for planes that don’t pass through the origin, but it’s not necessary for this problem since we can first translate the origin to $\mathbf P$, which won’t change the distances between points nor any of the plane normals.  
After translation, compute the dot products of each of the triangle’s vertices with $\mathbf N$ and use pairs for which the signs of the dot products differ to compute the two edge intersection points $\mathbf Q_1$ and $\mathbf Q_2$. Compare the signs of $\mathbf Q_1\cdot(\mathbf Q_2-\mathbf Q_1)$ and $\mathbf Q_2\cdot(\mathbf Q_2-\mathbf Q_1)$: If they are the same (or one of them vanishes), then the one with the least absolute value of this dot product is the nearest point on the line segment to $\mathbf P$. Otherwise, the nearest point on the segment is given by another application of formula (1): $$\mathbf R = {(\mathbf Q_1\cdot(\mathbf Q_2-\mathbf Q_1))\mathbf Q_2 - (\mathbf Q_2\cdot(\mathbf Q_2-\mathbf Q_1))\mathbf Q_1 \over \mathbf Q_1\cdot(\mathbf Q_2-\mathbf Q_1) - \mathbf Q_2\cdot(\mathbf Q_2-\mathbf Q_1)}.$$ If you only need the distance to $\mathbf R$ and not the point itself, you can compute that directly using the Pythagorean theorem: $$|\mathbf R|^2 = |\mathbf Q_1|^2 - \left(\mathbf Q_1\cdot{\mathbf Q_2-\mathbf Q_1 \over |\mathbf Q_2-\mathbf Q_1|}\right)^2 = |\mathbf Q_2|^2 - \left(\mathbf Q_2\cdot{\mathbf Q_2-\mathbf Q_1 \over |\mathbf Q_2-\mathbf Q_1|}\right)^2$$
