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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Plus de réponses (1)
Kunal Kandhari
le 22 Mai 2024
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.
1 commentaire
Voir également
Catégories
En savoir plus sur Polygons dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!