Create volume out of two surfaces

조회 수: 3 (최근 30일)
Kim
Kim 2019년 8월 21일
편집: Teerapong Poltue 2021년 6월 8일
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.
  댓글 수: 2
KSSV
KSSV 2019년 8월 21일
YOu want volume with cubes or tetrahedrons?
Kim
Kim 2019년 8월 21일
Since I want to be able to export it as stl tetrahedrons would be best.

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2019년 8월 21일
편집: Bruno Luong 2019년 8월 21일
Tetra mesh generation. Let you do exportation in STL file
% 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;
XYZI = cat(3,ones(n+1,1)*px, cos(t)*pyi, sin(t)*pyi);
XYZE = cat(3,ones(n+1,1)*px, cos(t)*py, sin(t)*py);
isbdri = false(size(XYZI,1),size(XYZI,2));
isbdri([1 end],:) = true;
isbdri(:,[1 end]) = true;
isbdre = false(size(XYZE,1),size(XYZE,2));
isbdre([1 end],:) = true;
isbdre(:,[1 end]) = true;
XYZI = reshape(XYZI,[],3);
n = size(XYZI,1);
XYZE = reshape(XYZE,[],3);
XYZ = [XYZI; XYZE];
isbdr = [isbdri; isbdre];
T = delaunay(XYZ);
b = T<=n;
keep = any(b,2) & any(~b,2) & sum(isbdr(T),2)<=3;
T = T(keep,:);
% This will take long time
close all
tetramesh(T,XYZ,'FaceColor','g')
  댓글 수: 2
Kim
Kim 2019년 8월 21일
Thank you very much!
Teerapong Poltue
Teerapong Poltue 2021년 6월 8일
편집: Teerapong Poltue 2021년 6월 8일
I tried to apply this code to my work, but it isn't work. Did you have any suggestion for my work.
I would like to connect two surfaces to be a solid, the it will be exported as an .stl file for futher CAD.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by