For anyone running into the same problem as me down the line, i figured out that i needed to sort the order of my faces, such that patch plots them in the order of transparency. The lines are then always shown for opaque elements, even if the adjacent element are transparent.
Edge lines not drawn when adjacent patch is transparent
2 次查看(过去 30 天)
显示 更早的评论
Hi!
I have a problem when rendering large 3D patches of cubes. Some of my patches are transparent and some are not. The edges drawn between vertices shared by a transparent face and a opaque face is not always shown. I've attached a small example of code showing this behaviour below, which mimics my full plot function.
clear; clc
FirstElementAlpha = 0.;
SecondElementAlpha = 0.8;
verts = [
0 0 0;
0 1 0;
0 0 1;
0 1 1;
1 0 0;
1 1 0;
1 0 1;
1 1 1;
2 0 0;
2 1 0;
2 0 1;
2 1 1;
];
faces = [
1 2 4 3;
2 4 8 6;
1 3 7 5;
5 6 8 7;
1 2 6 5;
3 4 8 7;
5 6 8 7;
6 8 12 10;
5 7 11 9;
9 10 12 11;
5 6 10 9;
7 8 12 11;
];
facealp = [
FirstElementAlpha*ones(6,1);
SecondElementAlpha*ones(6,1);
];
colormap pink
p = patch('Faces',faces,'Vertices',verts,'Facecolor','flat','EdgeAlpha','flat','FaceAlpha','flat', ...
'FaceVertexAlphaData',facealp,'FaceVertexCData',1-facealp,'Linewidth',2);
p.Parent.CLim = [0 1];
view(3)
axis equal
However, if flipping the transparancy of the two elements, all edges are shown.
I want the edges to always be drawn around faces, and the transparancy of this edge to be defined by the facealpha value. Im guessing that patch defines lines between vertices, and i overwrite a opaque line with a transparant line in my code.
Is there a way to keep the line with the largest alpha value?
Can i modify my plot function, to achieve this in another way?
0 个评论
采纳的回答
更多回答(1 个)
Kunal Kandhari
2024-5-22
Hi,
To ensure that the edges are always drawn around faces, regardless of the transparency of adjacent faces, you can set the 'EdgeAlpha' property of the patch object to a fixed value, rather than 'flat'. By doing this, you ensure that the edges will always have a consistent transparency level regardless of the transparency of adjacent faces.
In the code, change the value of 'EdgeAlpha' from 'flat' to 0.5.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!