5

I have generated a 3D plot of a surface using the ParametricPlot3D command.

Considering the three axes of the 3D plot to be x, y and z I would like to obtain a 2D plot showing surface boundaries for a specific z value.

Is there any relatively straightforward way to do that?

Sektor
  • 3,320
  • 7
  • 27
  • 36
AzurNova
  • 53
  • 3
  • 4
    Why not use ParametricPlot with fixed z instead of ParametricPlot3D? If it's a problem of coordinate transformations, it would be good to see an actual example with code you have already tried. – Jens Mar 08 '15 at 03:36
  • Are you trying to impose the 2D plot on top of the 3D plot? – Basheer Algohi Mar 08 '15 at 04:06
  • Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. – bbgodfrey Mar 08 '15 at 04:16
  • Why is this getting flagged for being reopened? The issues haven't been addressed, and it's over a year and a half old. – Feyre Nov 15 '16 at 13:19

5 Answers5

8

Here's a way to get the 2D graphics from an already-generated plot.

tori = ParametricPlot3D[{{4 + (3 + Cos[v]) Sin[u], 
     4 + (3 + Cos[v]) Cos[u], 4 + Sin[v]}, {8 + (3 + Cos[v]) Cos[u], 
     3 + Sin[v], 4 + (3 + Cos[v]) Sin[u]}}, {u, 0, 2 Pi}, {v, 0, 
    2 Pi}, PlotStyle -> {Red, Green}, Mesh -> None, 
   PlotStyle -> Thickness[0.1]];

With[{z0 = 4},
 RegionPlot3D[DiscretizeGraphics[tori], MeshFunctions -> {#3 &}, 
   Mesh -> {{z0}},
   MeshStyle -> {Directive[Thick, Blue]}, 
   PlotStyle -> None] /.
    Graphics3D[g_, opts___] :> 
     Graphics[g /. {x_Real, y_Real, z_Real} :> {x, y}, 
      FilterRules[{opts}, Graphics], Frame -> True]
 ]

Animation from Table[<plot code>, {z0, 0, 8, 0.2}]:

![Mathematica graphics](https://i.stack.imgur.com/ehRni.png)

Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • Pretty neat this. Bit more on z range would make first torus vanish altogether... Can we also get a table of x-,y- values for some z = constant section? Which independent variable is uniformly incremented in the section? – Narasimham Mar 08 '15 at 18:50
  • @Narasimham The z coordinate is increased (see Table code above animation). The x, y values can be obtained with Cases[regionplot, GraphicsComplex[pts_, __] :> pts, Infinity]. – Michael E2 Mar 08 '15 at 19:13
7

You can use ClipPlanes.

Using the same example from the docs as Zviovich:

tori = ParametricPlot3D[{{4 + (3 + Cos[v]) Sin[u], 
     4 + (3 + Cos[v]) Cos[u], 4 + Sin[v]}, {8 + (3 + Cos[v]) Cos[u], 
     3 + Sin[v], 4 + (3 + Cos[v]) Sin[u]}}, {u, 0, 2 Pi}, {v, 0, 
    2 Pi}, PlotStyle -> {Red, Green}];

Show[tori, ClipPlanes -> {{0, 0, -1, 4}}] 

Mathematica graphics

This seems a reasonable approach when computing the initial plot (tori) is expensive.

Michael E2
  • 235,386
  • 17
  • 334
  • 747
4
Show[{ParametricPlot3D[{{4 + (3 + Cos[v]) Sin[u], 
     4 + (3 + Cos[v]) Cos[u], 4 + Sin[v]}, {8 + (3 + Cos[v]) Cos[u], 
     3 + Sin[v], 4 + (3 + Cos[v]) Sin[u]}}, {u, 0, 2 Pi}, {v, 0, 
    2 Pi}, PlotStyle -> {Red, Green}, 
   RegionFunction -> Function[{x, y, z}, z < 4]], 
  ParametricPlot3D[{{4 + (3 + Cos[v]) Sin[u], 4 + (3 + Cos[v]) Cos[u],
      4}, {8 + (3 + Cos[v]) Cos[u], 3 + Sin[v], 4}}, {u, 0, 2 Pi}, {v,
     0, 2 Pi}, PlotStyle -> {Red, Green}]}]

enter image description here

Zviovich
  • 9,308
  • 1
  • 30
  • 52
3

Update: Using a combination of MeshFunctions, ViewPoint and PlotStyle:

ParametricPlot3D[{{4 + (3 + Cos[v]) Sin[u], 4 + (3 + Cos[v]) Cos[u], 4 + Sin[v]},
  {8 + (3 + Cos[v]) Cos[u], 3 + Sin[v], 4 + (3 + Cos[v]) Sin[u]}}, {u, 0, 2 Pi}, {v, 0, 2 Pi},
 ViewPoint -> {0, 0, Infinity}, MeshFunctions -> {Function[{x, y, z, u, v}, z]},
 Mesh -> {{{3.5, Directive[Thick, Red]}}}, Boxed -> False, Axes -> False, PlotStyle -> None]

enter image description here

Animate[ParametricPlot3D[{{4 + (3 + Cos[v]) Sin[u],  4 + (3 + Cos[v]) Cos[u], 4 + Sin[v]}, 
      {8 + (3 + Cos[v]) Cos[u], 3 + Sin[v], 4 + (3 + Cos[v]) Sin[u]}}, {u, 0, 2 Pi}, {v, 0, 2 Pi},
    ViewPoint -> {0, 0, Infinity},  MeshFunctions -> {Function[{x, y, z, u, v}, z]}, 
    Mesh -> {{{t, Directive[Thick, Red]}}}, Boxed -> False, 
    Axes -> False, PlotStyle -> None, PerformanceGoal -> "Quality"], 
 {t, 0., 8., .005}, 
 AnimationRate -> 2, AnimationRunning -> False,  AnimationDirection -> ForwardBackward]

enter image description here


Original post:

Also using Zviovich's example:

ParametricPlot3D[{ConditionalExpression[{4 + (3 + Cos[v]) Sin[u], 
                  4 + (3 + Cos[v]) Cos[u], 4 + Sin[v]},  Sin[v] < 0], 
  ConditionalExpression[{8 + (3 + Cos[v]) Cos[u], 3 + Sin[v], 
                       4 + (3 + Cos[v]) Sin[u]}, (3 + Cos[v]) Sin[u] < 0]},
 {u, 0, 2 Pi}, {v, 0, 2 Pi}, PlotStyle -> {Red, Green}, 
 PlotRange -> {Automatic, Automatic, {0, 8}}, MaxRecursion -> 6]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
0

I borrowed Zviovich's doughnuts to manipulate at variable $x$ Box limited Toric sections.

Manipulate[ParametricPlot3D[{{4+(3+Cos[v]) Sin[u],4+(3+Cos[v]) Cos[u],4+Sin[v]},{8+(3+Cos[v]) Cos[u],3+Sin[v],4+(3+Cos[v]) Sin[u]}},{u,0,2 Pi},{v,0,2 Pi},PlotStyle->{Yellow},Axes-> None, Boxed-> False,Mesh->{40,12},PlotRange-> {{0,xm},{0,8},{0,8}}], {xm,1,12,0.5}]

This may help to visualize 2D "Almost"

ParametricPlot3D[{{4 + (3 + Cos[v]) Sin[u], 4 + (3 + Cos[v]) Cos[u], 
   4 + Sin[v]}, {8 + (3 + Cos[v]) Cos[u], 3 + Sin[v], 
   4 + (3 + Cos[v]) Sin[u]}}, {u, 0, 2 Pi}, {v, 0, 2 Pi}, 
 PlotStyle -> {Yellow}, Axes -> None, Boxed -> False, 
 PlotRange -> {{xm - .1, xm}, {0, 8}, {0, 8}}, 
 PlotLabel -> "ALMOST_2D"]
Narasimham
  • 3,160
  • 13
  • 26