While plotting a slow to evaluate function and trying to get some sense of progress, I noticed that Mathematica traverses the grid of points twice. Here's the reduced example:
points = {};
Dynamic[
Show[
ListPlot[Take[points, Max[0, Length@points - 5]], PlotRange -> All],
ListPlot[
Take[points, -Min[Length@points, 5]], PlotRange -> All,
PlotStyle -> Directive[PointSize[Large], Opacity[0.1], Red]
],
AspectRatio -> Automatic
]
]
Monitor[
Plot3D[Pause[0.05]; 0, {a, -5, 5}, {b, -5, 5},
PlotRange -> All, PlotPoints -> 10, MaxRecursion -> 0],
AppendTo[points, {a, b}];
]
If you watch the plot, you'll see that the red points move twice over the grid. If you inspect the plots
variable after plotting, you'll see that not all the points are duplicates: some are offset from their originals by $\sim10^{-8}$.
Why does Plot3D
do this, even though I asked for MaxRecursion -> 0
? Is there any way to convince it to only scan the function once (not having to resort to ListPlot3D
+ Table
)?
f[x_, y_] := f[x, y] = ...
. $\endgroup$NormalsFunction -> None
as option. $\endgroup$VertexNormals
computed from the plot, instead of from the function, withRegion`Mesh`MeshCellNormals
. It helps to useMesh -> All
when converting the plot to a region:DiscretizeGraphics[Plot[..., Mesh -> All]]
. $\endgroup$