MATLAB Answers

Creating Caps to close a tubular structure

9 views (last 30 days)
Hi All
I have created this tubular shell structure in matlab.
I would like to create caps to close the end
[F,V] = surf2patch(x_All,y_All,z_All,'triangles');
h = patch('faces',F,'vertices',V);
set(h,'FaceColor',[0.5 0.5 0.8],'EdgeColor','k');


Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 19 Mar 2020
I cannot run your code.
Adapt this to your cylinder:
D = 10;
[X,Y,Z] = cylinder(D);
r = D;
ang = linspace(0, 2*pi);
xcirc = r*cos(ang);
ycirc = r*sin(ang);
zcirc = ones(size(ang))*max(Z(:));
surf(X, Y, Z)
hold on
patch(xcirc, ycirc, zcirc, 'r')
hold off
grid on
This creates a red ‘top’ to the cylinder. To cap it on the other end, duplicate the patch call, however substituting:
zcirc = ones(size(ang))*min(Z(:));
in the second call.


Conor O'Keeffe
Conor O'Keeffe on 20 Mar 2020
Thanks @Star Strider, that worked great
Star Strider
Star Strider on 20 Mar 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 19 Mar 2020
It sounds like you want isocaps. See this documentation page for more information.

  1 Comment

Conor O'Keeffe
Conor O'Keeffe on 20 Mar 2020
Hey Steven, thanks for your help. Yes, I was originally going to use that but couldnt figure out how to calculate the V part

Sign in to comment.

Sign in to answer this question.


Translated by