Space Curves and Contour Plots

Traces

Note: we saw the idea of traces last class, which are the mesh lines on the surface. We can color the two traces differently if we like:

Plot3D[4-x^2-y,{x,-4,4},{y,-4,4},AxesLabel->{"x","y","z"},MeshStyle->{{Thick,Red},{Blue,Thick}},BaseStyle->Large]

The blue lines are when the y coordinate is held fixed, so the trace is z = f(x, k) =4-(x^2)-k (parabolas opening down in the z x-plane), and the red lines are when the x coordinate is held fixed, so the trace is z=f(k,y)=4-(k^2)-y  (linear with negative slope in z y-plane).

You can do this for more complicated surfaces if you like:

Plot3D[(Sqrt[4-x^2+y^2]),{x,-4,4},{y,-4,4},AxesLabel->{"x","y","z"},MeshStyle->{{Thick,Red},{Blue,Thick}},BaseStyle->Large]

Intersections of Surfaces Leads to Space Curves

Here are two surfaces.

f[x_,y_]=4-x^2-y
g[x_,y_]=4-x-y^2

Here are the 3D plots of the surfaces:

plt1=Plot3D[f[x,y],{x,-4,4},{y,-4,4},AxesLabel->{"x","y","z"},BaseStyle->Large]
plt2=Plot3D[g[x,y],{x,-4,4},{y,-4,4},AxesLabel->{"x","y","z"},Mesh->False,BaseStyle->Large,PlotStyle->Directive[Yellow,Specularity[White,20],Opacity[0.8]]]

Here are the two plots together:

plt3=Show[plt1,plt2,ImageSize->{600,Automatic}]

We can easily see the two surfaces intersect each other, and the intersection line is given by a space curve.

The two surfaces interesect where f(x,y)=g(x,y).To plot the space curve, we will need to have a parametric representation of the space curve.

f[x,y]==g[x,y]

Combining this equation with the z=f(x,y) and z=g(x,y) equations allows us to find the relationships between x,y,z along the space curve. We want to solve these equations for the coordinates (x,y,z) and we will have a parameterization!

Solve[{z==f[x,y],z==g[x,y],f[x,y]==g[x,y]},{x,y,z}]

If Solve doesnt work, you can sometimes try Reduce, but it might be a bit more difficult to interpret.

∧ or && means "and"
∨ or || means "or"

Reduce[{z==f[x,y],z==g[x,y],f[x,y]==g[x,y]},{x,y,z}]

So we have two space curves as the solution, one is y=1-x, and z=-(x^2)+x+3 (x is the parameter in the parameterization) and the other is y=x, and y=x, and  z=-(x^2)-x+4. The parameterizations are the following:

x=t
y==1-t
z==-(t^2)+t+3

and

x=t
y==t
z==-(t^2)-t+4

Now we can do a 3D parametric plot of the space curves!

plt4=ParametricPlot3D[{t,t,-t^2-t+4},{t,-5,5},AspectRatio->1,AxesLabel->{"x","y","z"},PlotStyle->{Red,Thick}]

plt4a=ParametricPlot3D[{t,1-t,-t^2+t+3},{t,-5,5},AspectRatio->1,AxesLabel->{"x","y","z"},PlotStyle->{Blue,Thick}]

Now, let's overlay the space curves with the surfaces:

Show[plt3,plt4,plt4a]

Beautiful.

Example: Intersection of Plane and Half a Cylinder

Find the equation of the space curve that results from the intersection of the two surfaces given below. Also, sketch the space curve and the surfaces on one set of axes.

f[x_,y_]=1-x
g[x_,y_]=Sqrt[1-y^2]

Solution

Here are the 3D plots of the surfaces:

plt1=Plot3D[f[x,y],{x,-1,1},{y,-1,1},AxesLabel->{"x","y","z"},PlotPoints->30]
plt2=Plot3D[g[x,y],{x,-1,1},{y,-1,1},AxesLabel->{"x","y","z"},PlotPoints->30,Mesh->False,PlotStyle->Directive[Yellow,Specularity[White,20],Opacity[0.8]]]

Here are the two plots together:

plt3=Show[plt1,plt2,ImageSize->{600,Automatic}]

We can easily see the two surfaces intersect each other, and the intersection line is given by a space curve.

The two surfaces interesect where f(x,y)=g(x,y).To plot the space curve, we will need to have a parametric representation of the space curve.

f[x,y]==g[x,y]

Combining this equation with the z=f(x,y) and z=g(x,y) equations allows us to find the relationships between x,y,z along the space curve. We want to solve these equations for the coordinates (x,y,z) and we will have a parameterization!

Solve[{z==f[x,y],z==g[x,y],f[x,y]==g[x,y]},{x,y,z}]

So we have one space curve as the solution, one is x=1-(Sqrt[1-(y^2)]), and z=(Sqrt[1-(y^2)]) (y is the parameter in the parameterization).

x=1-(Sqrt[1-(t^2)])
y==t
z==(Sqrt[1-(t^2)])

Now we can do a 3D parametric plot of the space curves!

plt4=ParametricPlot3D[{1-Sqrt[1-t^2],t,Sqrt[1-t^2]},{t,-1,1},AspectRatio->1,AxesLabel->{"x","y","z"},PlotStyle->{Red,Thick}]

Now, let's overlay the space curve with the surfaces:

Show[plt3,plt4]

Application: Joining Surfaces in Computer Animations

The concept of intersecting surfaces is used in fluid dynamics, airplane construction, and computer animation. Here is a simple example that shows the utility in computer animation. I am sure that in practice this is done in a different manner, probably with a numerical algorithm, but you will see our way isn't too hard to figure out!

Let's clear some variables so we don't get incorrect results:

Clear[plt1,plt2,plt3,plt4,plt5,plt6,f,g]

Here is a surface:

f[x_,y_]=9-x^2-y^2;
plt1=Plot3D[f[x,y],{x,-4,4},{y,0,5},AxesLabel->{"x","y","z"},Mesh->False,PlotStyle->Directive[Yellow,Specularity[White,20],Opacity[0.8]]]

Here is another surface, which depends on the parameter s. As s varies the surface changes, and we get different intersections:

g[x_,y_,s_]=3(-s^2+2x s-x^2+1);
Do[
plt2[s]=Plot3D[g[x,y,s],{x,-5,5},{y,-3,5},AxesLabel->{"x","y","z"}],{s,-2,2,1/10}]

Here is an animation that shows one surface moving through another:

Manipulate[Show[plt1,plt2[s],ViewPoint->{0,1,2},PlotRange->{{-4,4},{-2,4},{-3,9}},ImageSize->{600,Automatic}],{s,-2,2,1/10}]

If this is a computer animation of an arm say, we would not want one surface protruding into another--we would like the surfaces to join where they intersect, and have no intrusion of one surface into another. We can get this to happen if we calculate the space curve for the intersection of the two surfaces.

Reduce[{f[x,y]==g[x,y,s],z==f[x,y],z==g[x,y,s]},{x,y,z}]

That was easy!

Now, we redefine the second surface to only be defined up until it hits the other surface:

g[x_,y_,s_]:=If[y>(Sqrt[3 (s^2)-6 x s+2 (x^2)+6]),3(-s^2+2x s-x^2+1)];

This will produce an animation of the space curve, once the parameter s is specified:

Do[
plt4[s]=ParametricPlot3D[{t,(Sqrt[3 (s^2)-6 t s+2 (t^2)+6]),-3 ((s^2)-2 t s+(t^2)-1)},{t,-5,5},AspectRatio->1,AxesLabel->{"x","y","z"},PlotStyle->{Red,Thick}],{s,-2,2,1/10}]

Here is the new animation, which includes the space curve where the two surfaces intersect.:

Manipulate[Show[plt1,plt2[s],plt4[s],ViewPoint->{0,1,2},PlotRange->{{-4,4},{-2,4},{-3,9}},ImageSize->{600,Automatic}],{s,-2,2,1/10}]

You cannot tell me that isn't cool!

Here is the new animation, which terminates both surfaces where they meet.

f[x_,y_]=If[9-x^2-y^2>-3 (-1+(s^2)-2 s x+(x^2)),9-x^2-y^2];
g[x_,y_,s_]=If[y>(Sqrt[3 (s^2)-6 x s+2 (x^2)+6]),3(-s^2+2x s-x^2+1)];
Do[
plt5[s]=Plot3D[g[x,y,s],{x,-5,5},{y,-3,5},AxesLabel->{"x","y","z"}];
plt6[s]=Plot3D[f[x,y],{x,-4,4},{y,0,5},AxesLabel->{"x","y","z"},Mesh->False,PlotStyle->Directive[Yellow,Specularity[White,20],Opacity[0.8]]]
,{s,-2,2,1/10}]

Manipulate[Show[plt6[s],plt4[s],plt5[s],ViewPoint->{0,1,2},PlotRange->{{-4,4},{-2,4},{-3,9}},ImageSize->{600,Automatic}],{s,-2,2,1/10}]

Contour Plots: Intersections of Surface with Planes parallel to x y-plane

The Contout Plot is just the trace in the x y-plane

Clear[plt1,plt2,plt3,plt4,plt5,plt6,f,g]

Contour plots are a very useful way to describe a surface. They essentially take the space curves that results from intersection of the surface with planes parallel to the x y- plane, and then drops all these space curves into the x y - plane. Here we see how it happens mathematically for a specific function.

f[x_,y_]=1
g[x_,y_]=2-x^2-y^2

Here, g is the surface and f is the plane parallel to the x y- plane (these planes all just have z= constant as their form).

Here are the 3D plots of the surfaces:

plt1=Plot3D[f[x,y],{x,-2,2},{y,-2,2},AxesLabel->{"x","y","z"},PlotPoints->30]
plt2=Plot3D[g[x,y],{x,-2,2},{y,-2,2},AxesLabel->{"x","y","z"},PlotPoints->30,Mesh->False]

Here are the two plots together:

plt3=Show[plt1,plt2,ImageSize->{600,Automatic}]

We can easily see the two surfaces intersect each other, and the intersection line is given by a space curve.

The two surfaces interesect where f(x,y)=g(x,y).To plot the space curve, we will need to have a parametric representation of the space curve.

f[x,y]==g[x,y]

Combining this equation with the z=f(x,y) and z=g(x,y) equations allows us to find the relationships between x,y,z along the space curve. We want to solve these equations for the coordinates (x,y,z) and we will have a parameterization!

Solve[{z==f[x,y],z==g[x,y],f[x,y]==g[x,y]},{x,y,z}]

So we have one space curve as the solution, since this is just

x=±(Sqrt[1-(y^2)])
z==1

Since x=±(Sqrt[1-(y^2)]) is the same as (x^2)+(y^2)=1 is just a circle in the x y - plane, a parameterization that contains both the top and bottom halves of the circle would be better, and we know one is:

x=cos(t)
y=sin(t)
z==1

Now we can do a 3D parametric plot of the space curves!

plt4=ParametricPlot3D[{Cos[t],Sin[t],1},{t,0,2Pi},AspectRatio->1,AxesLabel->{"x","y","z"},PlotStyle->{Red,Thick}]

Now, let's overlay the space curve with the surfaces:

Show[plt3,plt4]

Doing this for other planes z=k

If we do this for a bunch of planes z=k, then we get the following:

Solve[{z==k,z==g[x,y],k==g[x,y]},{x,y,z}]

Since x=± (Sqrt[-(y^2)-k+2])is the same as (x^2)+(y^2)=2-k, we can see that a parameterization for the space curve would be

x=(Sqrt[2-k])cos(t)
y=(Sqrt[2-k])sin(t)
z==k

which gives us circles with radius (Sqrt[2-k]) at height k.

rings=Table[{Sqrt[2-k]Cos[t],Sqrt[2-k]Sin[t],k},{k,2,-5,-1}];

plt5=ParametricPlot3D[Evaluate[rings],{t,0,2Pi},AspectRatio->1,AxesLabel->{"x","y","z"},PlotStyle->{{Red,Thick}}]

Show[plt2,plt5,ImageSize->{600,Automatic}]

A contour plot essentially looks at this sketch from directly above the origin:

Show[plt2,plt5,ImageSize->{400,Automatic},ViewPoint->{0,0,5}]

Here is Mathematica's much easier way of generating a contour plot. It contains the information about the height by shading the contour plot so that lower z values have a darker shading.

ContourPlot[g[x,y],{x,-2,2},{y,-2,2},ImageSize->{400,Automatic}]

Another Example of Contour Plot

Here is another function

g[x_,y_]=(Sqrt[4-x^2+y^2])

plt2=Plot3D[g[x,y],{x,-5,5},{y,-5,5},AxesLabel->{"x","y","z"},PlotPoints->30,Mesh->False,PlotStyle->Directive[Yellow,Specularity[White,20],Opacity[0.8]]]

If we do this for a bunch of planes z=k, then we get the following:

Solve[{z==k,z==g[x,y],k==g[x,y]},{x,y,z}]

Since x=± (Sqrt[4-(k^2)+(y^2)])is the same as (x^2) - (y^2) = 4 - (k^2), we can see that a parameterization for the space curve would be hyperbolas. You could set the parametrization up using cosh t and sinh t (the hyperbolic trig functions), but we will just work with what we found. We have two sets of space curves, one for x<0 and one for x>0.

x=(Sqrt[4-(k^2)+(y^2)])
y=y
z=k

x=-(Sqrt[4-(k^2)+(y^2)])
y=y
z=k

spacecurves1=Table[{(Sqrt[4-(k^2)+(y^2)]),y,k},{k,4,0,-1}];
spacecurves2=Table[{-(Sqrt[4-(k^2)+(y^2)]),y,k},{k,4,0,-1}];

plt5=ParametricPlot3D[{Evaluate[spacecurves1],Evaluate[spacecurves2]},{y,-5,5},AspectRatio->1,AxesLabel->{"x","y","z"},PlotStyle->{{Red,Thick}}]

Show[plt2,plt5,ImageSize->{600,Automatic}]

A contour plot essentially looks at this sketch from directly above the origin:

Show[plt2,plt5,ImageSize->{400,Automatic},ViewPoint->{0,0,5}]

Compare to Mathematica's ContourPlot:

ContourPlot[g[x,y],{x,-2,2},{y,-2,2},ImageSize->{400,Automatic}]

Another Example of a Contour Plot

Here is the surface:

g[x_,y_]=2-Cos[x y]Sin[y]

Here are the 3D plots of the surface:

plt2=Plot3D[g[x,y],{x,-3,3},{y,-3,3},AxesLabel->{"x","y","z"},PlotPoints->30,Mesh->False]

If we do this for a bunch of planes z=k, then we get the following for the contour lines:

Solve[{z==k,z==g[x,y],k==g[x,y]},{x,y,z}]

Crap. Can't do it for this function! Luckily, Mathematica's ContourPlot still works nicely.

ContourPlot[g[x,y],{x,-3,3},{y,-3,3},ImageSize->{400,Automatic}]