# Using mathematica to visualise solution of vectors and planes

Im struggling with a question I'm my math book and I wanted to use mathematica to visualise it for me, the problem is that I don't even get something remotely similar to what I was expecting. How here is the question and this is how I have visualised it. Could someone please show me the correct way also point out if it is the mathematics that is incorrect and why.

I have already looked at previous examples but some how I get stuck with this one. I know that there are several answers on the web but Im not able to use it to solve this.

So question, visualise the intersection of the planes.

eq1 = x + y == 2;
eq2 = y - z == 3;

{b, a} = CoefficientArrays[{eq1, eq2}, {x, y, z}];
point = LinearSolve[a, -b] // N;(*Solves for point on intersection*)
Cross @@ Reverse[a // Normal];(*Finds the direction vector of the plane*)
line = Graphics3D[{Red, Arrow[{point, 10 {1, -1, -1}}]}](*Draws the vector*)


Now what I was expecting was a red dot, somewhere along the line of intersection between the planes and a red vector being the line intersection for part of the planes intersection. (In particular line of length 10)

Show[Plot3D[x + y == 2, {x, -10, 10}, {y, -10, 10},
PlotStyle -> Blue],
Plot3D[y - z == 3, {y, -10, 10}, {z, -10, 10}, PlotStyle -> Green],
Graphics3D[{Red, Sphere[point]}], line,
PlotLabel -> "Point where surfaces meet", BoxRatios -> Automatic]


myPlanes = Graphics3D[
{{Opacity[0.5], Yellow,
Polygon[{{2, 0, -3}, {2, 0, 0}, {0, 2, 0}, {0, 2, -3}, {2,
0, -3}}]},
{Opacity[0.5], Blue,
Polygon[{{0, 0, -3}, {0, 3, 0}, {2, 3, 0}, {2, 0, -3}, {0,
0, -3}}]}},
Axes -> True,
AxesLabel -> {"x", "y", "z"}
]

myIntersection = ParametricPlot3D[{x, 2 - x, -x - 1}, {x, 0, 2},
PlotStyle -> Red]

Show[myPlanes, myIntersection]


• Would you be able to solve the problem in my code as well? – ALEXANDER May 5 '15 at 5:05
• @ALEXANDER I wouldn't address the problem by your fundamental method. – David G. Stork May 5 '15 at 5:06
• Could you explain why? – ALEXANDER May 5 '15 at 5:07
• @ALEXANDER For one thing, your constraint $x + y = 2$ does not define a function $z$, and hence cannot be plotted using Plot3D. – David G. Stork May 5 '15 at 5:18
• @ALEXANDER Think about it. Try to write a function $z = f(x,y)$ that describes the $x + y = 2$ constraint. You simply cannot do it. And Plot3D demands you cast your surface as Plot3D[z, {x, x0, x1}, {y, y0, y1}]. Go ahead... just try to do that! – David G. Stork May 5 '15 at 6:53

An embellished variant of @kajames' answer using ContourPlot3D:

cp = ContourPlot3D[{x + y == 2, y - z == 3}, {x, -10, 10}, {y, -10, 10}, {z, -10, 10},
ContourStyle -> {Directive[Blue, Opacity[0.5]], Directive[Green, Opacity[0.5]]},
Mesh -> False,
BoundaryStyle-> {1 -> None, 2 -> None, {1, 2} -> Directive[Thick, Cyan, Tube@@#&]}];
g3d = Graphics3D[{Red, Sphere@point, Arrow[Tube@{point, 10 {1, -1, -1}}]}];

Legended[Show[cp, g3d],
SwatchLegend[{Blue, Green}, Style[ToString@#, 16, "Panel"] & /@ {x+y == 2, y-z == 3}]]


Note: It seems that Plot3D silently transforms the first argument to x + y - 2 when passed x + y ==2 as the first argument:

Plot3D[x + y == 2, {x, -10, 10}, {y, -10, 10}] ==
Plot3D[x + y - 2, {x, -10, 10}, {y, -10, 10}]
(* True *)


To visualize the two planes generated by Plot3D and ContourPlot3D:

plt1 = Plot3D[x + y == 2, {x, -10, 10}, {y, -10, 10}, Mesh -> None,
PlotStyle -> Opacity[.5, Green]];
cp1 = ContourPlot3D[x + y == 2, {x, -10, 10}, {y, -10, 10}, {z, -10, 10},
Mesh -> None, ContourStyle -> Opacity[.5, Red]];
legend = SwatchLegend[{Green, Red}, Style[#, 16, "Panel"] & /@
{"Plot3D[x + y == 2, {x, -10, 10}, {y, -10, 10}]",
"ContourPlot3D[x + y \[Equal] 2, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}]"}];

Legended[Show[plt1, cp1, BoxRatios -> 1], legend]


Use ContourPlot3D to draw planes:

ContourPlot3D[x + y == 2, {x, -10, 10}, {y, -10, 10}, {z, -10, 10},
ContourStyle -> Directive[Blue, Opacity[0.5]], Mesh -> False]