How do I add colour to the faces of a patched shape

조회 수: 5 (최근 30일)
Jacob Vialou-Clark
Jacob Vialou-Clark 2018년 4월 17일
댓글: Jacob Vialou-Clark 2018년 4월 18일
figure(1)
v = [0 -20 60; 0 -20 56; 50 -10 60; 50 -10 56; 55 0 60; 55 0 56; -55 0 60; -55 0 56; -50 -10 60; -50 -10 56];
f = [1 2 4 3; 3 4 6 5; 5 6 8 7; 7 8 10 9; 1 2 10 9];
patch('Faces',f,'Vertices',v,'FaceAlpha',0);
I have this shape which is a simplified wing, how can I adapt the patch function to colour the faces?

채택된 답변

Robert U
Robert U 2018년 4월 18일

Hello Jacob Cialou-Clark:

as you specify a 3D faced object you have to take care which vertices you connect to faces. Right now, you define the mantle which cannot be seen directly from 2D plot via patch(). Another problem is that 'FaceAlpha',0 represents completely transparent faces.

In order to change that and have all faces of your 3D wing in 'red' you can change your code to:

 fh = figure(1);
 ah = axes('Parent',fh);
 v = [0 -20 60; 0 -20 56; 50 -10 60; 50 -10 56; 55 0 60; 55 0 56; -55 0 60; -55 0 56; -50 -10 60; -50 -10 56];
 f = [1 2 4 3 1; 3 4 6 5 3; 5 6 8 7 5; 7 8 10 9 7; 1 2 10 9 1; 1 3 5 7 9; 2 4 6 8 10];
 patch(ah,'Faces',f,'Vertices',v,'FaceAlpha',1,'FaceColor','red');
 ah.View = [45 45];

Kind regards,

Robert

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by