How to create a closed surface cylinder using patch function?
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Samson David Puthenpeedika
el 9 de Feb. de 2022
Comentada: Star Strider
el 10 de Feb. de 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;
0 comentarios
Respuesta aceptada
Star Strider
el 9 de Feb. de 2022
Try this —
%% Cylinder
[l,m,n]=cylinder;
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!