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