Example 6.4.5

This notebook illustrates the notion of the distance from a point to the plane discussed in example 6.4.5 of the textbook.  You enter the equation of a non-vertical plane by giving its left-hand side (where we place all the variables) and its right-hand side (which must be a number).  You also give the coordinates of the point whose distance to the plane needs to be found.

The manipulation then graphs the plane, the point you gave, and a number of other quantites.  First, it creates the normal line to the plane in green. It then creates a red point in the plane that you may move around via a 2-dimensional slider.  From this point it makes the vector from the red "point in plane" to the black point you entered, and forms the projection of this red vector onto the normal line (the projection itself is blue, and to aid with perspective the projection itself is shaded).  The length of this blue projection is the distance from the point to the plane.  Note that the blue projection (which represents the distance) never changes as the red point slides around in the plane.

PointtoPlane[ lhs_, rhs_, ptinspace_, param1_,param2_,{x_,y_,z_}]:=
Block[ {normal, distance, planeplot, graphics,movingpoint, closestpoint,t,max,min},
normal= {Coefficient[lhs,x],Coefficient[lhs,y],Coefficient[lhs,z]};
If[normal[[3]]==0, Print["This manipulation assumes the place is not vertical."]; Return[]]; 
distance=Abs[ normal.ptinspace-rhs]/Norm[normal];
closestpoint={x,y,z}/.Solve[ {{x,y,z}==ptinspace+t normal, lhs==rhs},{x,y,z,t}][[1]];
max=NMaximize[ {(rhs-normal[[1]]x-normal[[2]]y)/normal[[3]], closestpoint[[1]]-2distance≤ x≤ closestpoint[[1]]+2distance, closestpoint[[2]]-2distance≤ y≤ closestpoint[[2]]+2distance},{x,y}][[1]];
min=NMinimize[ {(rhs-normal[[1]]x-normal[[2]]y)/normal[[3]], closestpoint[[1]]-2distance≤ x≤ closestpoint[[1]]+2distance, closestpoint[[2]]-2distance≤ y≤ closestpoint[[2]]+2distance},{x,y}][[1]];
movingpoint={closestpoint[[1]],closestpoint[[2]],0}+ { 2param1 distance,  2param2 distance, z/. Solve[ {lhs==rhs, x==closestpoint[[1]]+ 2param1 distance, y== 2param2 distance+closestpoint[[2]]},{x,y,z}][[1]]};
planeplot=ContourPlot3D[lhs==rhs,{x,closestpoint[[1]]-distance, closestpoint[[1]]+distance},{y,closestpoint[[2]]-distance, closestpoint[[2]]+distance},
{z,min,max}, Mesh->None];
graphics={Green, Arrow[{closestpoint,ptinspace+normal/Norm[normal] distance}],Line[{closestpoint,closestpoint-normal/Norm[normal] distance}],PointSize[.035],Blue, Point[closestpoint], Arrow[ {closestpoint,ptinspace}], Red, Point[ movingpoint], Black, Point[ptinspace], Red, Arrow[ {movingpoint,ptinspace}], Opacity[.3], Polygon[ {movingpoint, closestpoint, ptinspace}]};
Column[{Row[{"The normal line intersects the plane at the blue point ",closestpoint}],Row[{"The distance from the black point to the blue point (i.e. distance to the plane) is ",distance}],Row[{"The current red point is ", movingpoint}],
Show[Graphics3D[graphics],planeplot, Axes->True, AxesLabel->{"x","y","z"}]}]
];

Manipulate[PointtoPlane[planelhs,planerhs,thepoint,param[[1]],param[[2]],{x,y,z}],{{planelhs,2x-3y+6z,"Plane left-hand side "}},{{planerhs,1,"Plane right-hand side"}},{{thepoint,{1,1,7},"The point"}},{{param,{.25,.25},"point in plane location"},{-.5,-.5},{.5,.5}}]