Saddle Contours

This notebook illustrates how to construct contour lines on a saddle plotted using ParametricPlot3D.

The saddle

This function for plotting the saddle uses polar coordinates, which leads to a circular coordinate system.  We will need to keep this in mind when working with the contours, since by default they are plotted in rectangular coordinates.  Note the fourth coordinate EdgeForm[ ] which suppresses the grid in ParametricPlot3D.  Cos[2 t] is used to give the saddle shape, that is it gives positive and negative z-values.  Using a large number of plot points insures a smooth surface and  minimizes the tendency of the contour lines to sink below the surface of the saddle in the final plot.

plot1 = 
      ParametricPlot3D[{r*Cos[t], r*Sin[t], r^2*Cos[2*t], EdgeForm[]}, {r, 0, 
          5}, {t, 0, 2  Pi}, PlotPoints  ->  {15, 45}, 
        BoxRatios  ->  {1, 1, 2}, 
        ImageSize  ->  360]

The contours

Here we need to choose our function carefully to insure that we have the same surface we created in the first plot.  I have set ContourShading to False to reduce the size of the output since we have no use for the shading information in our subsequent plots.  Using a large number of plot points insures that we get a good match of the contour lines with the edges of the saddle.

plot2 = 
      ContourPlot[x^2 - y^2, {x, -4, 4}, {y, -4, 4}, 
        Contours -> {-11, -9, -7, -5, -3, -1, 1, 
            3, 5, 7, 9, 11}, PlotPoints -> 50, 
        ContourShading -> False]

Here we use cases to extract the coordinates of the contour plot.  Note that we need to convert the ContourGraphics to Graphics to have the data in the correct form.  Infinity is included as a third argument to make sure we are getting lines at all depths of the list.

\(\(\(lns = Cases[\(Graphics[plot2]\)[\([1]\)], _Line, Infinity];\)\(
\)
    \)\)

The new contours

We need to construct ordered triples from our ordered pairs making sure that we supply z-values which correspond to those on the saddle.  In polar coordinates (r^2)= (x^2)+ (y^2)and the angle can be found using the two argument form of ArcTan.  To make sure the contour lines do not extend beyond the boundaries of the saddle plot we need to make sure that we take only those points which fall in a circle of appropriate radius, in this case 5.  The Select command is used to avoid error messages in the final plot.  The "+ .08" makes sure the contours stay on the surface of the saddle.  This value will have to be changed if the saddle is viewed from the underside.

lns3D = 
        Map[Select[#, # =!= Null &] &, 
          Map[If[#[[1]]^2 + #[[2]]^2 ≤  25, 
                Flatten[{#, (#[[1]]^2 + #[[2]]^2) Cos[
                          2 ArcTan[#[[1]], #[[2]]]] +  .08}], 
                Null] &, lns, {3}], {2}];

This creates the plot of the 3D contours.

plot2 = 
      Show[Graphics3D[lns3D], DisplayFunction -> Identity]

Now we combine the plots.

Show[{plot1, plot2}, BoxRatios -> {1, 1, 1}]

Distinguishing the contours

We can distinguish between the contours with positive and negative third coordinates by selecting the contours using Select.

poslns  = 
        Select[lns3D, #[[1, 1, 3]] ≥  0 &];

neglns  = Select[lns3D, #[[1, 1, 3]] <  0 &];

Now we "Show" the curves using color directives.

plot3  =  
      Show[Graphics3D[{{Hue[ .55], poslns}, {Hue[ .95], neglns}}], 
        DisplayFunction  ->  Identity]

And now we combine the plots.

Show[{plot1, plot3}, BoxRatios  ->  {1, 1, 2}]