필터 지우기
필터 지우기

How to create a closed surface cylinder using patch function?

조회 수: 30 (최근 30일)
I tried creating cylinder using patch fucntion but the top and bottom faces are open.
Below is my code-
%% Cylinder
[l,m,n]=cylinder;
fvc=surf2patch(l,m,n);
figure()
o=patch(fvc,'FaceColor','r');
o.FaceAlpha=0.2;

채택된 답변

Star Strider
Star Strider 2022년 2월 9일
Try this —
%% Cylinder
[l,m,n]=cylinder;
l = 2×21
1.0000 0.9511 0.8090 0.5878 0.3090 0.0000 -0.3090 -0.5878 -0.8090 -0.9511 -1.0000 -0.9511 -0.8090 -0.5878 -0.3090 -0.0000 0.3090 0.5878 0.8090 0.9511 1.0000 1.0000 0.9511 0.8090 0.5878 0.3090 0.0000 -0.3090 -0.5878 -0.8090 -0.9511 -1.0000 -0.9511 -0.8090 -0.5878 -0.3090 -0.0000 0.3090 0.5878 0.8090 0.9511 1.0000
m = 2×21
0 0.3090 0.5878 0.8090 0.9511 1.0000 0.9511 0.8090 0.5878 0.3090 0.0000 -0.3090 -0.5878 -0.8090 -0.9511 -1.0000 -0.9511 -0.8090 -0.5878 -0.3090 0 0 0.3090 0.5878 0.8090 0.9511 1.0000 0.9511 0.8090 0.5878 0.3090 0.0000 -0.3090 -0.5878 -0.8090 -0.9511 -1.0000 -0.9511 -0.8090 -0.5878 -0.3090 0
n = 2×21
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
figure()
surf(l,m,n)
hold on
patch(l(1,:),m(1,:),n(1,:),'r')
patch(l(2,:),m(2,:),n(2,:),'g')
hold off
title('Top End')
figure()
surf(l,m,n)
hold on
patch(l(1,:),m(1,:),n(1,:),'r')
patch(l(2,:),m(2,:),n(2,:),'g')
hold off
view(30,-30)
title('Bottom End')
The cylinder results are simply matrices of two vectors defining the top and bottom of the cylinder (unless a particular shape is supplied for the radius argument, then there are more rows to the cylinder output and only the first and last rows define the ends). To put ‘caps’ on either end, create separate patch objects for each end vector, and supply whatever colours are desired.
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by