Rendering a 3D shape by stacking 2D layers

9 次查看(过去 30 天)
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!

采纳的回答

Matt J
Matt J 2021-9-3
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 个评论
Matt J
Matt J 2021-11-10
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

请先登录,再进行评论。

更多回答(1 个)

DGM
DGM 2025-7-30
See also this later question on the same topic from the same user:

类别

Help CenterFile Exchange 中查找有关 Assembly 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by