Filling with colour the space inside object

 Accepted Answer

Perhaps you can adapt the solution in: fill area between two polar curves to your problem.

6 Comments

Thank you very much but I've only succeeded in filling the colour with 2D, but failed with 3D. Could you please give me a hint?
My code in 2D: patch([X1 X_arc1 fliplr(X2)], [Y1 Y_arc1 fliplr(Y2)],'g');
patch([X3 X_arc2 fliplr(X4)], [Y3 Y_arc2 fliplr(Y4)],'g');
My code in 3D: patch([X_1 X_arc1_new fliplr(X_2)], [Y_1 Y_arc1_new fliplr(Y_2)], [Z_1 Z_arc1_new fliplr(Z_2)], 'g');
patch([X_3 X_arc2_new fliplr(X_4)], [Y_3 Y_arc2_new fliplr(Y_4)], [Z_3 Z_arc2_new fliplr(Z_4)], 'g');
Add figure(3) to your code:
surffcn = @(x,y,H) surf([x;x],[y;y],[zeros(size(x)); ones(size(x))*H]); % Plots Surfaces
H = 0.5; % Height Of Sides
figure(3)
surffcn(X1,Y1,H)
hold on
surffcn(X2,Y2,H)
surffcn(X_arc1, Y_arc1,H)
surffcn(X3,Y3,H)
surffcn(X4,Y4,H)
surffcn(X5,Y5,H)
surffcn(X_arc2, Y_arc2,H)
patch([X1 X_arc1 fliplr(X2)], [Y1 Y_arc1 fliplr(Y2)],[ones(1,size(X1,2)*3)*H],'g');
patch([X3 X_arc2 fliplr(X4)], [Y3 Y_arc2 fliplr(Y4)],[ones(1,size(X3,2)*3)*H],'g');
hold off
axis('equal')
producing:
Note that you can make the height of the sides whatever you want by changing the ‘H’ value.
This only colours the upper surface. If you want to colour the lower surface as well, duplicate the two patch calls, and replace ‘H’ with 0 in only those two additional patch calls.
Thank you very much, now I want to convert it to file .stl but I don't know how. Could you please help me?
I have no idea how to convert it to a STL file, or even what a STL file is.
That was not part of your Question.
If it had been, I would have not have posted my Answer.
If my Answer in any way helped you solve your problem, please Accept it!
I am so sorry, I really appreciate you and your answer. Anyway, thank you so much for helping me
As always, my pleasure!

Sign in to comment.

More Answers (1)

DGM
DGM on 2 Jul 2025
Edited: DGM on 2 Jul 2025
I didn't notice that there were multiple questions posted on this. Here's my response to a different thread about the same project, including the STL output:

Asked:

on 16 Mar 2020

Edited:

DGM
on 2 Jul 2025

Community Treasure Hunt

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

Start Hunting!