In this answer I was trying to make a 3D stack of disk-shaped density plots, so I was using ListSliceDensityPlot3D. I resorted to using a set of nonrectangular grid points that were drawn from a unit circle, and the corresponding DensityPlot was circular. Something like this,

   {#1, #2, z, Sin[(#1 - #2) z]} & @@@ RandomPoint[Disk[], 1000],
   {z, 1, 11, 2}],
 {"ZStackedPlanes", Range[1, 11, 2]}

enter image description here

But this seems a bit klunky, and only results in nice disk-shaped slices as the number of random points gets larger.

What I'd like to do is take advantage of the ability to specify your own surfaces as the second argument to SliceDensityPlot3D or its list variant, rather than using "ZStackedPlanes".

I know that any 3D region can be used as a surface, so I want to create a disk-shaped surface. There isn't a built-in Disk3D function, but Taiki made such a function here.

disk3D[] creates a Polygon out of a set of

{ListPointPlot3D @@ #, Graphics3D@#} &@disk3D[]

enter image description here

Here are the results when I try to use these Polygon objects as surfaceregions, compared to the built-in stacked planes:

   Sin[(x - y) z], #, {x, -1, 1}, {y, -1, 1}, {z, 0, 12}, 
   PlotPoints -> 50] & /@ {disk3D[{0, 0, #}] & /@ 
   Range[1, 11, 2], {"ZStackedPlanes", Range[1, 11, 2]}}

enter image description here

We see a clear distortion of the function, and the resulting plot has little to no connection with the underlying density. I also receive repeated RegionIntersection::reg and RegionBounds::reg warnings. I can make these warnings go away by discretizing the regions before feeding them to SliceDensityPlot3D, but that only brings the problem into sharper relief:

SliceDensityPlot3D[Sin[(x - y) z], 
 DiscretizeGraphics[disk3D[{0, 0, #}]] & /@ Range[1, 11, 2], {x, -1, 
  1}, {y, -1, 1}, {z, 0, 12}]

enter image description here

The density plots seem to be sampled preferentially along the mesh lines created when discretizing the graphics:

DiscretizeGraphics[disk3D[{0, 0, 0}]]

enter image description here

This seems to clearly be a bug in SliceDensityPlot3D - one that is just as bad in SliceContourPlot3D. Increasing the number of PlotPoints does not have an effect.

How can I turn the disk3D object into a surface in a better way? Is there any way to ensure that the discretized graphics has a better mesh function?

For the record, it is possible to get the plot by the circuitous route of first creating a ListContourPlot3D object for each disk, discretizing that to create a surface region (again using Quiet because of the errors) - thanks to Szabolcs. Using this code (omitted here for brevity), we can see that it is necessary to get a very fine mesh to get a decent plot:

enter image description here

But that code is very slow, and I'd like to be able to use the Polygon objects instead.


1 Answer 1


You can significantly speed things up by using DiscretizeRegion on ImplicitRegion.

 Sin[(x - y) z], 
 {DiscretizeRegion@ImplicitRegion[x^2 + y^2 <= 1 && z == #, {x, y, z}] & /@ 
    Range[1, 11, 2]},
 {x, -1, 1}, {y, -1, 1}, {z, 0, 12}]

enter image description here

It will work without DiscretizeRegion but does not produce as fine density slices and also requires Quiet in that case.

Hope this helps.

Actually you can stack any family of 2D regions with this method. For example:

 Sin[(x - y) z], {DiscretizeRegion@
       #/100 <= x^2 + y^2 <= 1 && 
         Abs[x] > #/100 && 
         z == #, 
      {x, y, z}] & /@ Range[1, 11, 2]}, 
 {x, -1, 1}, {y, -1, 1}, {z, 0, 12}]

enter image description here

  • $\begingroup$ Very cool - so the answer is to, if possible, discretize a regionwith DiscretizeRegion rather than a graphics via DiscretizeGraphics $\endgroup$
    – Jason B.
    Commented Feb 19, 2016 at 13:21
  • $\begingroup$ @JasonB That seems to be the case. It also works on 3D regions without DiscretizeRegion. However, the faces are not as fine. $\endgroup$
    – Edmund
    Commented Feb 19, 2016 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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