Effacer les filtres
Effacer les filtres

How to create a closed surface cylinder using patch function?

30 vues (au cours des 30 derniers jours)
Samson David Puthenpeedika
Commenté : Star Strider le 10 Fév 2022
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;

Réponse acceptée

Star Strider
Star Strider le 9 Fév 2022
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.
.
  2 commentaires
Samson David Puthenpeedika
Samson David Puthenpeedika le 10 Fév 2022
Thankyou so much
Star Strider
Star Strider le 10 Fév 2022
As always, mmy pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by