As explained here, given a plane:
ax + by + cz + d = 0
and a point x0=( x0 , y0, z0 ), the normal vector to the plane is given by:
v = [ a ; b ; c ]
and a vector from the plane to the point is given by:
w = -[ x-x0 ; y-y0 ; z-z0 ]
Projecting w onto v gives the (shortest) distance D from the point to the plane as:
D = ( ax0 + by0 + cz0 + d ) / ( sqrt( a2 + b2 + c2 ) )
The question is simple: how to fit the point x0 to the plane, i.e. how to move it to ( x , y, z ) position, which is the closest point lying on the plane to x0.
The equation of the line is:
And the intersection of the line with the plane is given by:
Just need to find t and substitute it in the line equation to find the point ( x , y, z ).