Matlab图形问题:半散点,红色区域内的黑线

Matlab figure problems: half scatter points, black lines inside a red region

在Matlab中考虑下图(矩阵here

load matrices
%Rb, vertices_deg, vertices_comp

close all
patch([0 0 1],[0 1 0],[1 0 0],[0.8 0.8 0.8]);
axis equal 
axis([0 1 0 1 0 1])
view(120,30)
hold on

T = delaunayTriangulation(Rb.');
K = convexHull(T);
patch('Faces',K,'Vertices',T.Points,'FaceColor','k','edgecolor','k');
hold on

scatter3(vertices_deg(:,1), vertices_deg(:,2) , vertices_deg(:,3),100,'o','filled','b')
hold on

patch(vertices_comp(:,1), vertices_comp(:,2) , vertices_comp(:,3),'red')
hold off

xlim([0 1])
ylim([0 1])
zlim([0,1])
box on
set(gca, 'ytick',0:0.2:1,'xtick',0:0.2:1,'ztick',0:0.2:1,'FontSize',13)

我想以这样的方式保存这个数字:

我尝试了两种保存图形的方法

saveas(gcf,'3.jpg')
print(gcf, '3.jpg', '-dpng', '-r300', '-painters') 

None 这两个给了我我想要的。你能帮忙吗?

这就是我用 PRINT 得到的结果

这就是我使用 SAVEAS 得到的结果

这里是 Matlab 的屏幕截图 window

您看到的问题是,这些补丁是在完全相同的平面上绘制的,这导致了这种渲染效果。这叫做Z-fighting

一个简单的解决方法是为绘制在其他平面之前的一些平面添加一些小的偏移量。您可以调整此值,直到效果消失,并且缩进位置的错误最小。

load matrices

close all
patch([0 0 1],[0 1 0],[1 0 0],[0.8 0.8 0.8]);
axis equal 
axis([0 1 0 1 0 1])
view(120,30)
hold on

T = delaunayTriangulation(Rb.');
K = convexHull(T);

d_patch = 0.001;
d_z = 0.01;

patch('Faces',K,'Vertices',T.Points + d_patch,'FaceColor','k','edgecolor','k');
patch(vertices_comp(:,1), vertices_comp(:,2) , vertices_comp(:,3)+d_z,'red')

scatter3(vertices_deg(:,1), vertices_deg(:,2) , vertices_deg(:,3),100,'o','filled','r')
scatter3(vertices_deg(:,1), vertices_deg(:,2) , vertices_deg(:,3)+2*d_z,100,'o','filled','b')

xlim([0 1])
ylim([0 1])
zlim([0,1])
box on
set(gca, 'ytick',0:0.2:1,'xtick',0:0.2:1,'ztick',0:0.2:1,'FontSize',13)

saveas(gcf,'3saveas.png')
print(gcf, '3print.png', '-dpng', '-r300', '-painters') 

您可以对部分绘制到平面中的蓝点执行相同的操作。只要给它一点偏移,它就会再次显示为一个完整的点。我用红色和蓝色绘制了这个点,所以你可以看到位置偏移。