7
$\begingroup$

The documentation for ListSliceDensityPlot3D says

ListSliceDensityPlot3D[{{x1,y1,z1,f1},{x2,y2,z2,f2},…},surf] generates a slice density plot for the values $f_i$ at points $\{x_i,y_i,z_i\}$.

But what if my surface is defined only numerically?

list1 = Table[{x, y, z, x^2 + y^2 - z^2}, {x, -1, 1, .05}, {y, -1, 
     1, .05}, {z, -1, 1, .05}]~Flatten~2;
surface1 = First @ ListContourPlot3D[list1, Contours -> {0.3}];
Graphics3D @ surface1 

enter image description here

This seems clearly to be a surface, so let's try to use it in ListSliceDensityPlot3D:

ListSliceDensityPlot3D[
 Table[Exp[-3^2 ((x - .3)^2 + (y - .3)^2 + (z - .3)^2)],
  {x, -1, 1, .1}, {y, -1, 1, .1}, {z, -1, 1, .1}],
 surface1]

I get the error

ListSliceDensityPlot3D::slice: "Slice specification GraphicsComplex[<<1>>] should be a named slice, surface or volume region, or list of slices."

and it uses the default slices

enter image description here

Of course in this example I could use ImplicitRegion[x^2 + y^2 - z^2==0.3,{x,y,z}] to define the surface,

ListSliceDensityPlot3D[
 Table[Exp[-3^2 ((x - .3)^2 + (y - .3)^2 + (z - .3)^2)],
  {x, -1, 1, .1}, {y, -1, 1, .1}, {z, -1, 1, .1}],
 ImplicitRegion[x^2 + y^2 - z^2 == 0.3, {x, y, z}],
 DataRange -> {{-1, 1}, {-1, 1}, {-1, 1}}]

enter image description here

but what if I don't have the equation, but only the data? If I try to define the ImplicitRegion using an interpolation function it does not work.

I can't apply DiscretizeRegion to the contour plot, what can I do to extract the surface?

$\endgroup$
5
  • $\begingroup$ I want to have an object that I can use as a surface for ListSliceDensityPlot3D. When I define surf = First@ListContourPlot3D[list1, Contours -> {0.3}] and then try to use it via ListSliceDensityPlot3D[list2, surf] I get the error "Slice specification GraphicsComplex[<<1>>] should be a named slice, surface or volume region, or list of slices." $\endgroup$
    – Jason B.
    Commented Feb 4, 2016 at 10:37
  • $\begingroup$ I will edit it to make it more clear :-) $\endgroup$
    – Jason B.
    Commented Feb 4, 2016 at 10:39
  • $\begingroup$ @Kuba - see this question, which could end up closed even though it is a valid question. Rahul pointed out it could be done with ListSliceDensityPlot3D and I just want to try and do so. $\endgroup$
    – Jason B.
    Commented Feb 4, 2016 at 10:48
  • $\begingroup$ @Kuba, yeah, I know there's a way to do it, I just wonder how far you can go using this new function. Please avoid extended discussions in comments lol $\endgroup$
    – Jason B.
    Commented Feb 4, 2016 at 10:51
  • $\begingroup$ Ahh, right, I though that is something you problably know. Well, the documentation states you can only use regions so the question can be narrowed down to "how to convert contour plot 3d to region". $\endgroup$
    – Kuba
    Commented Feb 4, 2016 at 10:52

1 Answer 1

8
$\begingroup$

One way is to create a region using DiscretizeGraphics.

g = ListContourPlot3D[list1, Contours -> {0.3}]

Now DiscretizeGraphics[g] gets upset and refuses to work because of the GraphicsComplex inside of g. We can get rid of that using Normal, so let's try:

surf = DiscretizeGraphics@Normal[g]

Mathematica graphics

It still gets upset because of some directives, but it appears to handle the surface part properly. This is a region so we can use it in SliceDensityPlot3D:

SliceDensityPlot3D[x^2 + y^2 + z^2, surf, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Thanks! I didn't try DiscretizeGraphics but it would have failed anyway without Normal. How did you know you would have to use Normal? Experience with this, or more of a workflow: If it fails, try it with Normal $\endgroup$
    – Jason B.
    Commented Feb 4, 2016 at 11:32
  • $\begingroup$ @JasonB The error message says that GraphicsComplex is not supported. Normal expands the GraphicsComplex (see last entry under Details on its documentation page). $\endgroup$
    – Szabolcs
    Commented Feb 4, 2016 at 11:38

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.