1
$\begingroup$

When you combine 2D plots using Show overlapping data will be shown in the order that the plots/objects are provided to Show (later argument appears further in the foreground). When making 3D plots the same does not happen instead the closest object is always shown on the foreground. Is there a way to instead always bring one plot/object to the foreground from any viewpoint?


Minimal example:

SeedRandom[1234];
pts1 = RandomPoint[Cuboid[{0, 0, 0}, {1, 1, 1}], 100];
pts2 = RandomPoint[Cuboid[{0.5, 0.5, 0.5}, {0.6, 0.6, 0.6}], 100];
pts = Union[
   pts1, pts2
   ];
Show[
 ListPointPlot3D[pts, PlotRange -> All, PlotStyle -> Opacity[0.5]],
 HighlightMesh[
  DelaunayMesh[pts2[[-10 ;;]]], {Style[1, Red], Style[2, Red]}]
 
 ]

Which produces enter image description here

I would like the DelaunayMesh to be clearly visible as if it was in the foreground. I understand that I can play with the Opacity of the points but the point is to find a solution where the DelauneyMesh is simply always in the foreground. Fine tuning the opacity of every object to make the Mesh visible while the points themselves are still possible is not a solution. So I would like a solution where the Opacity of the points is actually 1. I just put it at 0.5 to show at least somewhat clearly the shape of the DelaunayMesh. Instead I would like to view the DelauneyMesh as if there was nothing else in front of it at all. (This is a simplified example of course and there are many objects involved in the real case.)

$\endgroup$

2 Answers 2

3
$\begingroup$

For 3D objects their positions are fixed in 3D space. You cannot change their relative position without changing their definitions. However you can emphasize one over the other by making one more or less transparent.

Manipulate[
 Show[
  Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
   PlotStyle -> Opacity[opac]],
  Plot3D[{x^2 + y^2, -x^2 - y^2}, {x, -2, 2}, {y, -2, 2},
   PlotStyle -> Red]],
 {{opac, 0.5, "Opacity"}, 0, 1, 0.05,
  Appearance -> "Labeled"},
 SynchronousUpdating -> False]

enter image description here

$\endgroup$
4
  • $\begingroup$ I tried getting the object to stand out this way but in my case it is impossible. There are too many points and lines close to a small object that I want to stand out. So I am still looking for a solution. I guess that for one fixed viewpoint I might be able to emphasize one object by cheating and making kind of cylinder towards the viewer of the projection. $\endgroup$
    – Kvothe
    Commented Mar 30, 2021 at 9:55
  • $\begingroup$ I think the easiest option might be to consider it a problem of combining two 2D graphics. So first we export two 3D plots (same viewpoints but one only contains the object to be emphasized and the other the rest) to for example .png and then we have to add one on top of the other. This should be doable. $\endgroup$
    – Kvothe
    Commented Mar 30, 2021 at 10:37
  • $\begingroup$ Without a concrete example that is representative of the issue, it is difficult to propose anything. $\endgroup$
    – Bob Hanlon
    Commented Mar 30, 2021 at 13:31
  • $\begingroup$ I added a minimal example to illustrate the problem. (There is of course always a balance between finding a minimal example that can be posted in the limited space available on StackExchange and the true problem but I think if a solution can be found to the minimal problem (that does not come down to simply reducing the Opacity of the other points) it should also apply to my real case. $\endgroup$
    – Kvothe
    Commented Mar 30, 2021 at 13:51
0
$\begingroup$

I think combining 2D graphics might be the easiest way to achieve this. The following produces a decent result:

SeedRandom[1234];
pts1 = RandomPoint[Cuboid[{0, 0, 0}, {1, 1, 1}], 100];
pts2 = RandomPoint[Cuboid[{0.5, 0.5, 0.5}, {0.6, 0.6, 0.6}], 100];
pts = Union[
   pts1, pts2
   ];

plt1 = ListPointPlot3D[pts, PlotRange -> All, PlotStyle -> Opacity[1]];
plt2 = Show[
   ListPointPlot3D[pts, PlotRange -> All, PlotStyle -> Opacity[0]]
   , HighlightMesh[
    DelaunayMesh[pts2[[-10 ;;]]], {Style[1, Red], Style[2, Red]}]
   ];
Show[Image[plt1], Image[plt2]]

enter image description here

(Of course it requires that we first fix the angle that we want since the result is no longer a 3D plot.)

$\endgroup$

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.