[Math] Shortest distance between a 3D parametric surface and a point

3dparametric

Right now I'm working on a library for finding the distances between objects in Lua. I've had some trouble finding the distance between a point and a bounded plane. I'm using these parametric equations:

$$
\mbox{plane}(s_0,t) = (x_0, y_0, z_0) + s
\le(x_1, y_1, z_1) + t(x_2, y_2, z_2),
\quad 0 \le (s_0, t) \le 1
$$

and

$$
\mbox{point}(s_1)
= (x_3, y_3, z_3) + s(x_4, y_4, z_4),
\quad 0 \le s_1 \le 1
$$

I know that the projection of a line segment from any point on the plane to the point-I-want-to-find-the-distance-from onto the normal of the plane will give me the distance from a point to an unbounded plane.

In an attempt to solve my problem, I said that the point on the plane that is closest to my point is my point plus the inverse of the projection onto the normal. I would then solve the values of s and t to see if they where greater then one. If so, then I would try to find the distance from the 4 points in the plane, and use the line between the two closest points to my point to find the distance between my point and bounded plane. This is very inefficient.

So my question, is there a more direct way to solve the distance between a point and a surface/bounded plane?

Best Answer

It's best if you write the plane equation in the form $(\mathbf x - \mathbf p)\cdot \mathbf n = 0$, where $\mathbf p$ is a point on the plane and $\mathbf n$ is a unit normal. You can easily get this form from the one you're currently using. Use your point $(x_0,y_0,z_0)$ as $\mathbf p$, and use a unitized cross product of your vectors $(x_1,y_1,z_1)$ and $(x_2,y_2,z_2)$ as the unit normal $\mathbf n$.

Then suppose you have some point $\mathbf q$, and you want to find its distance to the plane. The (signed) distance is $(\mathbf q - \mathbf p) \cdot \mathbf n$. If you don't care about the sign, take the absolute value.

The expression you wrote for your "point" actually represents a line, not a point.

You can find C++ code on this page