Filling with colour the space inside object

 Respuesta aceptada

Star Strider
Star Strider el 16 de Mzo. de 2020

0 votos

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

6 comentarios

Anh Phan Viet
Anh Phan Viet el 16 de Mzo. de 2020
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.
Anh Phan Viet
Anh Phan Viet el 16 de Mzo. de 2020
Thank you very much, now I want to convert it to file .stl but I don't know how. Could you please help me?
Star Strider
Star Strider el 16 de Mzo. de 2020
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!
Anh Phan Viet
Anh Phan Viet el 16 de Mzo. de 2020
I am so sorry, I really appreciate you and your answer. Anyway, thank you so much for helping me
Star Strider
Star Strider el 16 de Mzo. de 2020
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (1)

DGM
DGM el 2 de Jul. de 2025
Editada: DGM el 2 de Jul. de 2025

0 votos

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:

Etiquetas

Preguntada:

el 16 de Mzo. de 2020

Editada:

DGM
el 2 de Jul. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by