7
$\begingroup$

I’m having a hard time eliminating some moiré-like artifacts from the 3D output of ListDensityPlot3D.

Here is an example:

n = 1.5;
ρCore = 166;
bdElectronDensityConversion = 5.25*^23*ρCore;
ξCore = $MachineEpsilon;
R = 8.26*^9*Quantity["cm"];
M = 0.04*Quantity["SolarMass"];
K = (M^(1/3)*R*Quantity["GravitationalConstant"])/2.3573;
a = Sqrt[((n + 1)*(K*(ρCore*Quantity["g/cc"])^((1 - n)/n)))
         /(4*Pi*Quantity["GravitationalConstant"])];
ξRadius = (QuantityMagnitude[UnitConvert[R]]
               /QuantityMagnitude[UnitConvert[a]]);
system = {Dt[ξ^2*Derivative[1][θ][ξ], {ξ}]/ξ^2 == -θ[ξ]^n,
          θ[ξCore] == 1,
          Derivative[1][θ][ξCore] == 0};
sol = NDSolve[system, θ, {ξ, ξCore, ξRadius}][[1]];



Rkm = QuantityMagnitude@UnitConvert[R, "km"];
Show[DensityPlot3D[
    (bdElectronDensityConversion*θ[Sqrt[(x*ξRadius/Rkm)^2
    + (y*ξRadius/Rkm)^2 + (z*ξRadius/Rkm)^2]]^n /. sol),
    {x, y, z} ∈ RegionDifference[
        Ball[{0, 0, 0}, Rkm], Cuboid[{0, -Rkm, 0}, {Rkm, Rkm, Rkm}]], 
    PerformanceGoal -> "Quality", PlotPoints -> 100, 
    OpacityFunction -> None, 
    ColorFunction -> ColorData[{"SolarColors", {1*^25, 8*^25}}], 
    ColorFunctionScaling -> False], ImageSize -> Large]

When I run this code, I see this: Note moiré artifacts

Sadly, moiré artifacts run throughout the cutaway faces of the ball, giving the false impression that a non-spherically-symmetric structure exists in the solution. This could mislead anyone hoping to interpret the plot!

I’d greatly appreciate any advice on eliminating these artifacts. I’ve tried increasing PlotPoints, to no avail.

Thanks!

$\endgroup$
5
  • 1
    $\begingroup$ How long does the graphic take to generate on your machine? (my question isn't related to the answer of your question, but I just let it run for a few minutes with no success... if it takes minutes to test each thing it might make the problem difficult to troubleshoot!) $\endgroup$
    – ktm
    Commented Nov 30, 2018 at 4:32
  • 1
    $\begingroup$ Do you really need to use ListDensityPlot if you're only going to show a cutaway? You can speed this plot by orders of magnitude by just plotting on the sphere surface and cutting planes. $\endgroup$ Commented Nov 30, 2018 at 6:23
  • 1
    $\begingroup$ @user6014: I’ve reduced PlotPoints to 100 in the example, since this still exhibits the moiré artifacts. It takes about 1 min 40 s to run on my machine. $\endgroup$
    – Daine
    Commented Nov 30, 2018 at 19:35
  • $\begingroup$ @DavidG.Stork: That would help for this example, but sadly the full code includes a ListDensityPlot3D displaying data, which exhibits the same moiré artifacts. If you know of a comparable workaround for that case, however, it could be very helpful indeed. $\endgroup$
    – Daine
    Commented Nov 30, 2018 at 19:43
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Commented Dec 16, 2018 at 20:41

1 Answer 1

4
$\begingroup$

Maybe this?:

MapAt[
 Rotate[#, -2 Pi/3, {1, 1, 1}] &@Scale[#, {1, -1, 1}] &, 
 SliceDensityPlot3D[(bdElectronDensityConversion*θ[
         Sqrt[(x*ξRadius/Rkm)^2 + (y*ξRadius/
               Rkm)^2 + (z*ξRadius/Rkm)^2]]^n /. x -> -x /. sol) //
    Evaluate, {"CenterCutSphere"}
  , {z, -Rkm, Rkm}, {x, -Rkm, Rkm}, {y, -Rkm, Rkm},
  ColorFunction -> ColorData[{"SolarColors", {1*^25, 8*^25}}], 
  ColorFunctionScaling -> False, AxesLabel -> RotateLeft@{z, x, y}
  ],
 1]

Mathematica graphics

Unfortunately, "CenterCutSphere" is a cut with respect to the azimuthal angle only, so conjugation by some geometric transformations is necessary.

$\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.