Create volume out of two surfaces
Show older comments
I'm trying to create a volume out of two surfaces for a parameter study. The volume should also be exportable as stl-file. The code for the surfaces is shown below.
% Points in xy-plane
nx = 100;
px = linspace(1,50,nx);
pyi = 5+sin(0.8*px);% inside
py = 6+sin(0.8*px);% outside
% rotation x-axis
n=25;
t=(0:n)'*0.5*pi/n;
figure;
surf(ones(n+1,1)*px,cos(t)*pyi,sin(t)*pyi);% inside
hold on
surf(ones(n+1,1)*px,cos(t)*py,sin(t)*py);% outside
I tried to apply the code from Filling area between two planes in 3d plot but I'm not able to make it work. If I use the code below, I get the error report that the indices on the left side are not compatible with the size of the right side at the line v3(r,c,s) = min(d1,d2);
%%Create 3D grid containing distance to closest surface
[x,y,z] = ndgrid(linspace(0,50,nx),linspace(0,50,nx),linspace(0,50,nx));
v = zeros(size(z));
for r=1:n+1
for c=1:n+1
for s=1:n+1
d1 = z(r,c,s) - sin(t)*pyi(r,c);
d2 = sin(t)*py(r,c) - z(r,c,s);
if d1 < 0
v3(r,c,s) = d1;
elseif d2 < 0
v3(r,c,s) = d2;
else
v3(r,c,s) = min(d1,d2);
end
end
end
end
%%Create isosurface
figure
p = [patch(isosurface(y,x,z,v3,0)), ...
patch(isocaps(y,x,z,v3,0))];
isonormals(y,x,z,v3,p(1))
set(p,'FaceColor','yellow')
set(p,'EdgeColor','none')
set(p,'FaceLighting','gouraud')
view(3)
camlight right
I'd be very grateful for your help.
Accepted Answer
More Answers (0)
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
