필터 지우기
필터 지우기

Edge lines not drawn when adjacent patch is transparent

조회 수: 1 (최근 30일)
cTroels
cTroels 2024년 5월 22일
답변: cTroels 2024년 5월 23일
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?

채택된 답변

cTroels
cTroels 2024년 5월 23일
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.

추가 답변 (1개)

Kunal Kandhari
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.
  댓글 수: 1
cTroels
cTroels 2024년 5월 22일
편집: cTroels 2024년 5월 22일
But wouldnt that also draw all edges as opaque around the transparant element? I want the transparancy of the lines sorrounding a face being the same as the transparancy of the face itself

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by