Rendering a 3D shape by stacking 2D layers

9 visualizaciones (últimos 30 días)
승준 이
승준 이 el 3 de Sept. de 2021
Respondida: DGM el 30 de Jul. de 2025
I am new to using MATLAB, so I am not used to specific programming functions here. I am trying to render a 3D-shaped model by stacking 2D layers. The original 2D polar plot to start with looks like this:
t = 0:0.01:2*pi;
r = sin(t).^3 + cos(t).^3;
polar(t,r)
Or, we could also use the cartesian coordinate system instead of the polar coordinate system by using this:
I will call this layer a 'bean shape'.
The goal is to create similar bean shapes and stack them continuously in the z axis to create a 3D model. (Maybe a cartesian coordinate system should be used.)The ratio of similarity will follow y=sin(z) from 0 to pi. (So the shape starts with 0 at the bottom, becomes bigger as z increases, biggest at z=pi/2, and becomes smaller again.) The biggest layer would be the same as r = sin(t).^3 + cos(t).^3 since the ratio of similarity would be y=1. For an easier understanding, I will use 7 discrete bean shapes. Shape #1 goes on the very bottom in the z axis, then on top of Shape #1 goes Shape #2, and then #3, #4, ..., #7 (Which would be the biggest layer). On top of #7 goes #6, then #5, #4, ... #1.
The only difference is that we are not using 7 discrete layers, but stacking an infinite amount of layers (from z=0 to z=pi) continuously (which is same as integration).
I would also like to know how to calculate the volume of the 3D shape after rendering this. Thanks in advance!

Respuesta aceptada

Matt J
Matt J el 3 de Sept. de 2021
One way would be to use fimplicit3:
fun=@(x,y,z) (x.^2+y.^2).^(2)-(x.^3+y.^3).*sin(z);
fimplicit3(fun);
zlim([0,pi])
  8 comentarios
Matt J
Matt J el 10 de Nov. de 2021
I don't know about surf2stl, but with stlwrite
you should be able to do,
x=-1:0.01:1;
y=-1:0.01:1;
z=-0:0.01:3;
[X,Y,Z]=meshgrid(x,y,z);
V=fun3D(X,Y,Z);
I=isosurface(x,y,z,V,0) ;
stlwrite('fun.stl',I);
function out=fun3D(x,y,z)
fun2D=@(x,y) (x.^2+y.^2).^(2)-(x.^3+y.^3);
fun2D=@(x,y) fun2D(x+0.25,y+0.25);
s=@(q) min(q./sin(z),1e6);
out=fun2D(s(x),s(y));
end
승준 이
승준 이 el 11 de Nov. de 2021
Thank you very much.

Iniciar sesión para comentar.

Más respuestas (1)

DGM
DGM el 30 de Jul. de 2025
See also this later question on the same topic from the same user:

Categorías

Más información sobre Assembly en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by