# Orthogonal Projection of vector onto plane

Posted 3 months ago
924 Views
|
9 Replies
|
2 Total Likes
|
 I'm currently trying to learn Mathematica, and I've got some linear algebra tasks to solve with it. I've gotten quite far but now I'm stuck on this one exercise. The instructions are:With the help of Mathematica-commands, draw a new picture, where you can see the orthogonal projection of the vector onto the plane. It should look something like this: Now, I started out by drawing the vector in the 3D plane with this code: Graphics3D [ { Thick , Arrow [ { { 0 , 0 , 0} , { 1 , −1 , 2 } } ] , InfinitePlane [ { { 1 , 0 , 0} , { 1 , 1 , 1} , { 0 , 0 , 1 } } ] } , Axes −> True , AxesLabel −> { "X" , "Y" , "Z" } ] This gave me the 3D image in the picture above, without the projection (the dashed line) obviously. But now I'm stuck, and my question is, how would I get the orthogonal projection of the vector?Thanks in advance.
9 Replies
Sort By:
Posted 3 months ago
 You have the following points pp = {1, -1, 2}; p1 = {1, 0, 0}; p2 = {1, 1, 1}; p3 = {0, 0, 1}; The plane is given by plane = p1 + (p2 - p1) u + (p3 - p1) v; and the normal to the plane normal = Cross[p2 - p1, p3 - p1]; To find the point xx (in the plane) where the normal passes through point pp solve sol = Solve[ Join[Thread[ Cross[pp - plane, normal] == {0, 0, 0}], {normal.(pp - plane) == normal.normal tau}], {u, v, tau}] // Flatten to find In[85]:= xx = plane /. sol Out[85]= {0, 0, 1} Now you have to find the point, where your vector hits the plane sol2 = Solve[Thread[plane == pp tau], {u, v, tau}] In[117]:= px = Flatten[pp tau /. sol2] Out[117]= {1/4, -(1/4), 1/2} and try to make a nice pic Show[ ParametricPlot3D[plane, {u, -.5, .5}, {v, -.3, 1.5}, PlotStyle -> Opacity[.5]], Graphics3D[{Red, PointSize[.04], Point[px], Point[xx], Point[pp], Arrow[{px, xx}], Arrow[{pp, xx}], Blue, PointSize[.06], Point[{0, 0, 0}], Thickness[.01], Arrow[{{0, 0, 0}, pp}]}], PlotRange -> All] 
Posted 3 months ago
 Hey, thank you for the very detailed answer. Everything is very clear and I now understand how to get to projection onto the plane. But there is one thing though, in the exercise my 3D plane should look like the picture I posted above. That's what I need help with now. Thanks in advance :)
Posted 3 months ago
Posted 3 months ago
 Fine that I could help you and things became clearer. should look like the picture I posted above You should play around with the u and v in the Plot3D-command, or turn the plot around with the mouse until it fits, or try this (play around with the coordinates of ViewPoint and see what happens) Show[ ContourPlot3D[ normal.{x, y, z} == normal.plane, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, ContourStyle -> Opacity[.5], ViewPoint -> {1.3, -5.4, 2}], Graphics3D[{Red, PointSize[.04], Point[px], Point[xx], Point[pp], Arrow[{px, xx}], Arrow[{pp, xx}], Blue, PointSize[.06], Point[{0, 0, 0}], Thickness[.01], Arrow[{{0, 0, 0}, pp}]}], PlotRange -> All] 
Posted 3 months ago
 Hey. Thanks for the reply. I've got a problem with the code costed abow that I can't seem to figure out. Whenever I type in this: sol = Solve[ Join[Thread[ Cross[pp - plane, normal] == {0, 0, 0}], {normal.(pp - plane) == normal.normal tau}], {u, v, tau}] // Flatten I get a message saying Solve: {1,-1,2} is not a valid variable. Why is that?
Posted 3 months ago
 No idea. Depends on your session. Seems somewhere you have redefined sol. Try Clear[sol] sol = Solve[ Join[Thread[ Cross[pp - plane, normal] == {0, 0, 0}], {normal.(pp - plane) == normal.normal tau}], {u, v, tau}] // Flatten 
Posted 3 months ago
 Hmm, doesn't work. But I've gotten it to work with the help of some people over at stackexchange, but I haven't really gotten a good explanation of what the functions do, as I have here. Would you mind taking a look at it? This is how my code looks like at the moment: p0 = {0, 0, 0}; p1 = {1, -1, 2}; p2 = {1, 0, 0}; p3 = {1, 1, 1}; p4 = {0, 0, 1}; gr1 = Graphics3D[{Thick, Arrow[{p0, p1}],InfinitePlane[{p2,p3,p4}]},Axes -> True, AxesLabel-> {"X", "Y","Z"}]; v = p1 - p0; n1 = p2 - p3; n2 = p3 - p4; n = Cross[n1, n2]; pl = p0; pp = p2; equs = Thread[pl + lambda v == pp + mu n1 + nu n2]; sol = Solve[equs, {lambda, mu, nu}][[1]]; pb = p0 + lambda v /. sol; vern = n/Norm[n]; prjn = (v.vern) vern; prjP = v - prjn; gr2 = Graphics3D[{Thick, Dashed, Red, Arrow[{pb, prjP + pb}]}]; Show[gr1, gr2] Now, what I don't understand are the code from the equs variable, down to the prjP variable. Do you think you could try clarifying it a bit for me?
 Would I mind? In a certain sense yes, because you are supposed to strive for explanations yourself. For instance look up the descriptions of the functions used.But ok, here we are p0 = {0, 0, 0}; (* Origin *) p1 = {1, -1, 2}; (* Position of Head of Arrow *) p2 = {1, 0, 0}; (* Three points defining your plane *) p3 = {1, 1, 1}; p4 = {0, 0, 1}; gr1 = Graphics3D[{Thick, Arrow[{p0, p1}], PointSize[.05], Point /@ {p2, p3, p4} }, Axes -> True, AxesLabel -> {"X", "Y", "Z"}]; (* Graphics. my version Mma 7 doesn't know InfinitePlane, so I changed it to Point \ *) v = p1 - p0; (* Head of vector. equals p1, therefore v is not \ necessary*) n1 = p2 - p3; (*basevectors of plane, better n1=p3-p2*) n2 = p3 - p4;(* better p4-p2 *) n = Cross[n1, n2]; (* normal to plane *) pl = p0; (* not necessary, , pl equals p0 = {0,0,0} *) pp = p2; (* not necessary, pp equals p2 *) equs = Thread[pl + lambda v == pp + mu n1 + nu n2]; (* pl + lambda v = {0,0,0} + lambda p1 is the equation of a line thru \ {0,0,0 } in direction of your vector *) (* if this line reaches the plane it must fulfill the equation of the \ plane: lambda v == plane =p2+.... . Thread makes three equations out \ of one *) sol = Solve[equs, {lambda, mu, nu}][[1]]; (* solve it vor lamda , mu, nu *) pb = p0 + lambda v /. sol; (* calculate the point where the vector meets the plane. could be \ done as well by plane/.sol *) vern = n/Norm[n]; (* normalized normal to plane *) prjn = (v.vern) vern; (*Projection of vector to normal *) prjP = v - prjn; (* vec orthogonal to normal, lying in the plane: prjP.n ->0, prjP + \ prjn gives v = vector, so you have vector decomposed in a component \ lying in the plane and one component parallel to the normal of the \ plane *) gr2 = Graphics3D[{Thick, Dashed, Red, Arrow[{pb, prjP + pb}]}]; Show[gr1, gr2]