In 3-space, a plane abc is spanned by three points a, b, c. The point x does not lie on this plane.

I'm trying to find the formulas used to find the point p on abc with minimal distance to x.

I know the point p must be perpendicular to the point p and the plane.

So, I began with taking a vector from the plane to the point, w:

x = (x0,x1,x2)
p = (p0,p1,p2) <-- unknown

w = [p0-x0, p1-x1, p2-x2]

v = [a, b, c] = [a0 b0, c0]
[a1, b1, c1]
[a2, b2, c2]

then I project w onto v

D = |(v dot w)|/|v|

but my problem arises here because I do not know the distance and I do not know the coordinates of p. Am I supposed to be using the gradient formula instead?

Any help is greatly appreciated! Thank you

First shift everything by minus a, so that the plane goes through the origin. The plane then goes through the points:

b'= b - a

and

c'= c - a

and through the origin.

Then, we define an orhonormal basis for the linear space spanned by the plane. We take the first basis vector to be in the direction of b'. So we normalize b1 to obtain:

e1 = b'/|b'|

From c' we subtract the component in the direction of e1:

f2 = c' - (c' dot e1) e1

Then f2 is orthogonal to e1:

f2 dot e1 = c'dot e1 -
(c' dot e1) (e1 dot e1.

Now, e1 dot e1 = 1, because e1 is normalized. So we see that
f2 dot e1 =0.

Then we have to normalize f2 to get the second basis vector:

e2 = f2/|f2|

You can now simply project the point x'= x-a onto the plane to obtain p':

p' = (x' dot e1) e1 + (x' dot e2) e2

Then shift back by a to obtain p:

p = p'+ a

To find the point p on the plane abc with the minimum distance to the point x, you can follow these steps:

1. Define the vector w from the plane abc to the point x:
w = x - a (or w = x - b, or w = x - c)

2. Find the normal vector n of the plane abc. You can do this by taking the cross product of two vectors on the plane, for example, n = (b - a) × (c - a).

3. Now, we want to find the vector p that lies on the plane abc and is perpendicular to w. This means that the dot product of the vectors w and p should be zero.
w · p = 0

4. We can express the vector p as a linear combination of the two vectors on the plane abc, let's call them u and v.
p = u + v

5. Substitute p in the dot product equation:
w · (u + v) = 0

6. Distribute the dot product:
(w · u) + (w · v) = 0

7. Note that u and v are vectors on the plane abc, so the dot product of w with u or v should be zero. This is because the dot product of any vector on the plane abc with the normal vector n is zero.
w · u = 0
w · v = 0

8. Now we have a system of equations:
(w · u) + (w · v) = 0
w · u = 0
w · v = 0

9. Solve this system of equations to find the vectors u and v.

10. Once you have u and v, you can find the point p on the plane abc by adding u and v to any point on the plane, for example, p = a + u (or p = b + v, or p = c + u).

Using this method, you can find the point p on the plane abc with the minimal distance to the point x.