Avoiding surface zig-zag/aliasing when plotting
I'm trying to plot a surface that has a deep ravine, but at each point at the bottom it then jumps back up due to the steep nature of the surface. This causes lots of what I'm calling zig-zags, and ends up causing visual aliasing as pictured here.
The code I'm using to produce this makes a first x axis, then defines the y axis as using the inverse of the surface function using x axis such that each minimum of the surface is present in the data (they're all zeros). These are put into meshes and then the function is plotted.
rangeX = linspace(0,1,1000);
rangeY = invfunc(rangeX);
[meshX, meshY] = meshgrid(rangeX, rangeY);
for nn=1:1000
for mm=1:1000
surfaceZ = func(meshX(nn,mm),meshY(nn,mm));
end
end
surf(meshX, meshY, surfaceZ)
Is there any way around this other than just pushing the resolution to crazy levels? I don't want to wait forever for the script to run.
Through changing the shading, setting 'LineStyle','none' and upping the resolution the effect is much better.
Posted Aug 9, 2018, 12:45 PM UTC · edited
What's the problem - the dark line at the center of the ravine or the noticeable difference between colors outside of the ravine?
The aliasing and zigzag of the ravine when viewed from the side.
Ah, OK. I can't view it from the side because I can't run the code (I don't know what "func" and "invfunc" are) and I didn't scroll down far enough to notice the second image. The Zig-Zags are a realistic depiction of your function, no? What do you want it to look like?
Oh it’s not real code just pseudo code, I just wanted to demonstrate something similar. The zig zags are caused by the lines drawn between the points of the surface. Now that you make me think of it maybe it would be better as a scatter plot because it’s the interpolation that causes the effect...
Edit: scatter plots don't work because there are fewer points at the bottom than the top. I think the original method might just have to be how it is.