Why does changing certain parameters while invoking 'plot3' function reduce the smoothness of the plotted curve?

I was trying to use 'plot3' function to plot a 3-dimensional curve. Changing some of the parameters in the function call creates the issue of smoothness loss in the curve plotted. One of the cases wherein this is observed is while setting 'alpha' of a patch to transparency.
The following code snippet creates two subplots where the first subplot appears to be smooth, whereas the second one is not.
topx = [0 0.1415 -0.1415];
topy = [-0.1640 0.0815 0.0815];
kns = [0 0.5958 -0.5958; -0.6880 0.3440 0.3440; 0 0 0];
pfmx = [0 0.1 -0.1];
pfmy = [0 0.1 -0.2];
pfmz = -0.1;
basex = [-0.2829 0.2829 0]
basey = [ -0.1640 -0.1640 0.3270]
figure,
subplot(121)
hold on, grid on
f.base = patch(basex,basey,[.4 .4 .4]);
% f.base.FaceAlpha = 0.75;
f.base.EdgeColor = 'none';
view(3)
f.legs = plot3([topx(1),kns(1,1),pfmx(1)],[topy(1),kns(2,1),pfmy(1)],[0,kns(3,1),pfmz],'b-',...
[topx(2),kns(1,2),pfmx(2)],[topy(2),kns(2,2),pfmy(2)],[0,kns(3,2),pfmz],'b-',...
[topx(3),kns(1,3),pfmx(3)],[topy(3),kns(2,3),pfmy(3)],[0,kns(3,3),pfmz],'b-','linewidth',3);
subplot(122)
hold on, grid on
f.base = patch(basex,basey,[.4 .4 .4]);
f.base.FaceAlpha = 0.5;
f.base.EdgeColor = 'none';
view(3)
f.legs2 = plot3([topx(1),kns(1,1),pfmx(1)],[topy(1),kns(2,1),pfmy(1)],[0,kns(3,1),pfmz],'b-',...
[topx(2),kns(1,2),pfmx(2)],[topy(2),kns(2,2),pfmy(2)],[0,kns(3,2),pfmz],'b-',...
[topx(3),kns(1,3),pfmx(3)],[topy(3),kns(2,3),pfmy(3)],[0,kns(3,3),pfmz],'b-','linewidth',3);
Why is this behavior observed? Is this a bug?

 采纳的回答

The issue is due to transparency coupled with 'SortMethod'.
In the first subplot, the lines appear to be smooth as they are anti-aliased. Anti-aliasing allows pixels to be partially colored along the edges of the line to provide a smoother looking line.
In the second subplot, as transparency is added, the Axes are automatically switching the 'SortMethod' to 'Depth'. Unfortunately, anti-aliasing is not supported by the depth sorting method.
For more information, have a look at the following blog post about 'SortMethod':
As a workaround, you can attempt to switch the 'SortMethod' to 'childorder', which would produce smoother looking lines. However, this may significantly change how the scene is rendered (as described the blog post).

更多回答(0 个)

类别

产品

版本

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by