Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have two issues with the following code. (1) It executes too slowly. If I use "Speed" instead of "Quality" for PerformanceGoal, I get the speed but an undesirable delay in proper rendering of the contour. Perhaps the calculation of the expression to be contoured is the cause of the slowness. If so, can that be accelerated? (2) How can I make the z-axis vertical. Note its appearance with some jaggies.

Manipulate[  
    ContourPlot3D[
    {z == 10*x*y*Exp[-x - y], z == k}, {x, 0, 6}, {y, 0, 6}, {z, 0, 3}, 
    ContourStyle -> {Red, Opacity[0.9]},
    AxesOrigin -> {0, 0, 0}, Boxed -> False, Mesh -> None, 
    PerformanceGoal -> "Quality",
    MeshStyle -> Directive[Thick], AxesStyle -> Directive[Thick], 
    BoundaryStyle -> Directive[Blue], ContourStyle -> Opacity[0.8],
    ViewPoint -> {-4, -8, 4}, ImageSize -> 2 {420, 370}],
    {{k, 0.5, Text@Style["k", Italic, FontSize -> 18]}, 0, 1.35, 0.01, 
    Appearance -> "Labeled"}
 ]
share|improve this question

3 Answers 3

up vote 5 down vote accepted

The nature of the function you've provided makes ContourPlot3D an overkill. Use Plot3D and set the ViewPoint -> 100 {-4, -8, 4} a little further to make the z axis straight.

Manipulate[
 Show[Plot3D[10*x*y*Exp[-x - y], {x, 0, 6}, {y, 0, 6}, Mesh -> None, PlotStyle -> Red], 
      Graphics3D[{FaceForm[Directive[Blue, Opacity[.5]]], EdgeForm[Directive[Thick, Blue]], 
                  Dynamic@Polygon[{{0, 0, k}, {0, 6, k}, {6, 6, k}, {6, 0, k}}]}], 
      AxesOrigin -> {0, 0, 0}, Boxed -> False, ViewPoint -> 100 {-4, -8, 4}, 
      ImageSize -> {420, 370}, AxesStyle -> Directive[Thick]], 
 {{k, 0.5, Text@Style["k", 18]}, 0, 1.35, 0.01, Appearance -> "Labeled"},
 SynchronousUpdating -> False]

enter image description here

share|improve this answer

Nasser gives good standard ControlActive approach. But that by definition looses quality during motion. I just would like to share a trick that avoids that. Most of the time is spent on rendering your bell shape. But it is static. Plane moves but it is simple, so it should not all the time trigger recomputing of static bell shape. You can separate motion of plane from bells shape with Dynamic. This will allow you to move without loss of quality during motion.

Manipulate[

 Show[

  ContourPlot3D[
   z == 10*x*y*Exp[-x - y], {x, 0, 6}, {y, 0, 6}, {z, 0, 3}, 
   ContourStyle -> Red, Mesh -> None, PerformanceGoal -> "Quality"],

  Graphics3D[{FaceForm[Directive[Blue, Opacity[.5]]], 
    EdgeForm[Directive[Thick, Blue]], 
    Dynamic@Polygon[{{0, 0, k}, {0, 6, k}, {6, 6, k}, {6, 0, k}}]}],

  AxesOrigin -> {0, 0, 0}, Boxed -> False, 
  AxesStyle -> Directive[Thick], ViewPoint -> {-4, -8, 4}, 
  ImageSize -> {420, 370}]

 , {{k, 0.5, Text@Style["k", Italic, FontSize -> 18]}, 0, 1.35, 0.01, 
  Appearance -> "Labeled"}, SynchronousUpdating -> False]

enter image description here

share|improve this answer
    
@Vitally Kaurov - Motion is too jerky. See Kuba's use of Plot3D instead of ContourPlot3D –  Stephen May 30 at 11:14
    
@Stephen i've seen it - it is a nice idea working in this case. but that's not the point of my post. in some situation you will not be able to replace ContourPlot3D with Plot3D. –  Vitaliy Kaurov May 30 at 13:25
    
@Vitally Kaurov - Since my surface has the form f(x,y)-z=0, there is no point in using ContourPlot3D which must calculate the points to plot by some implicit method. –  Stephen May 30 at 18:27
    
@Stephen I know that ;) I was trying to share a general useful trick. And as you can see even Kuba adopted it for his code - in addition to his idea. Because it often makes things better. –  Vitaliy Kaurov May 30 at 18:30
    
@Stephen yep, the question title still states about seeding up the contour plot :) –  Kuba Jun 1 at 9:55

You can speed things up by using ControlActive on some of the options which slows down things. Like this

Manipulate[
 ContourPlot3D[{z == 10*x*y*Exp[-x - y], z == k}, {x, 0, 6}, {y, 0, 6}, {z, 0, 3},
  ContourStyle -> {Red, Opacity[0.9]}, AxesOrigin -> {0, 0, 0},
  Boxed -> False, Mesh -> None,
  PerformanceGoal -> ControlActive["Speed", "Quality"],
  Contours -> ControlActive[3, 10],
  PlotPoints -> ControlActive[3, 10],
  MeshStyle -> Directive[Thick],
  AxesStyle -> Directive[Thick],
  BoundaryStyle -> Directive[Blue],
  ContourStyle -> Opacity[0.8],
  ViewPoint -> {-4, -8, 4},
  ImageSize -> {420, 370}],

 {{k, 0.5, Text@Style["k", Italic, FontSize -> 18]}, 0, 1.35, 0.01, 
    Appearance -> "Labeled", ContinuousAction -> True}
 ]

If you also change ContinuousAction -> True to False that will speed it up more.

enter image description here

see http://reference.wolfram.com/mathematica/tutorial/AdvancedDynamicFunctionality.html

The idea is to wrap those options which can slow down things using ControlActive with values that are low as first argument, which will cause the plot to update fast as the slider is moving, but when the slider stops, the second argument is used giving the better final looking plot (but slower to render)

share|improve this answer
    
Your first answer was better; the edited version produces too crude an approximation to the level curves. Kuba used Plot3D instead of ContourPlot3D. –  Stephen May 30 at 11:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.