2
$\begingroup$

Bug introduced in 12.2 or earlier, persisting through 13.2.


I am modeling a simple system: the potential from a sphere of charge Q as a function of position. SliceDensityPlot3D with the "CenterCutBox" option almost gives a gorgeous output, and except for the clutter on the right facing surfaces it does exactly what I want: gives a sense of the potential both on the surface and interior to the cube. I have tried different PlotPoints, to no avail.

In the SliceDensityPlot3D documentation under "scope -> surfaces -> Standard boundary surfaces" a table with the three boundary surfaces is provided, and which looks fine in the documentation page (no surprise). When I use the exact same code in my own notebook, I get the same spurious output (!).

As another try, I used a cylinder, however I could not get that to appear smooth and also there is no centercut cylinder.

I am running version 12.2.0.0 on Win 10 pro. Thanks in advance!

a = 5 10^-5; 
q1 = 1.602 * 10^-12;
eps0 = 8.85418781 * 10^-12; 
qEnclosed1[r_] := If[r < a, (q1 r^3)/a^3, q1];
eField1[r_] := qEnclosed1[r]/(4 \[Pi] r^2 eps0);
potSphereTEMP[r_] = -Integrate[eField1[r], r ];
potInfinity = Limit[potSphereTEMP[r], {r -> \[Infinity]} ];
potSphere[r_] := potSphereTEMP[r] - potInfinity 
potSphereCartesian[x_, y_, z_] := potSphere[Sqrt[x^2 + y^2 + z^2]]
SliceDensityPlot3D[
 potSphereCartesian[x, y, z], "CenterCutBox" , {x, -3.0 a, 
  0.0 a}, {y, -1.5 a, 1.5 a}, {z, -1.5 a, 1.5 a}, 
 ColorFunction -> "Rainbow"] (* my plot *)

SliceDensityPlot3D[potSphereCartesian[x, y, z], 
 Cylinder[{{-3. a, 0., 0.}, {0., 0., 0.}}, a], {x, -3.0 a, 
  0.0 a}, {y, -1.5 a, 1.5 a}, {z, -1.5 a, 1.5 a}, 
 ColorFunction -> "Rainbow", 
 Method -> {"CylinderPoints" -> {200, 
     200}}]  (* another version of my plot *)

Table[SliceDensityPlot3D[Sin[x] + y^2 - z^3, 
  sl, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, 
  PlotLabel -> sl], {sl, {"CenterSphere", "CenterCutSphere", 
   "CenterCutBox"}}]  (* copied direction from documentation *)

Output from main part of the notebook

$\endgroup$
2
  • $\begingroup$ BoundaryStyle -> None. $\endgroup$
    – cvgmt
    Jun 23, 2023 at 1:23
  • $\begingroup$ This is a confirmed bug. (I mean the output of CenterCutBox. ) $\endgroup$
    – xzczd
    Jun 25, 2023 at 6:52

1 Answer 1

5
$\begingroup$

The issue with the Cylinder surface can be fixed using exact numbers:

SliceDensityPlot3D[potSphereCartesian[x, y, z], 
 Cylinder[{{0, 0, 0}, {-3 a, 0, 0}}, a], 
 {x, -3 a, 0}, {y, -3/2 a, 3/2 a}, {z, -3/2 a, 3/2 a}, 
 ColorFunction -> "Rainbow", 
 Method -> {"CylinderPoints" -> {200, 200}}]

enter image description here

The issue with "CenterCutBox" can be fixed using BoundaryStyle -> None (as in this Q/A):

SliceDensityPlot3D[
 potSphereCartesian[x, y, z], "CenterCutBox",
 {x, -3.0 a, 0.0 a}, {y, -1.5 a, 1.5 a}, {z, -1.5 a, 1.5 a}, 
 BoundaryStyle -> None, ColorFunction -> "Rainbow"] 

enter image description here

SliceDensityPlot3D[Sin[x] + y^2 - z^3, "CenterCutBox",
 {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, BoundaryStyle -> None]

enter image description here

$\endgroup$
2
  • $\begingroup$ This got me going again, @kglr, thanks so much. My only question, really out of curiosity more than necessity, is why I need to add "BoundaryStyle -> None" and that is not included in the docs. May there is a background setting I am not using? $\endgroup$
    – Jack Adams
    Jun 23, 2023 at 14:51
  • $\begingroup$ @JackAdams, I could not find any reference in the docs either. I found by accident (using BoundaryStyle->Green) that those spurious lines are boundary lines. $\endgroup$
    – kglr
    Jun 23, 2023 at 15:41

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.