How to turn 3D surface into STL file with surface?

The attached MATLAB code produces a 3D surface. How can I give the surface some thickness and export it as an STL file?
% Data points forming a figure eight in 3D space
x = [-54 -58 -47 -43 -54 -65 -61 -50 -54];
y = [ 20 32 38 26 20 13 1 7 20];
z = [ 82 76 82 88 82 76 82 88 82];
% Plot the data points and write their serial numbers
n = length(x);
plot3(x,y,z,'r-*'), axis equal
hold on
for i = 1:n, text(x(i),y(i),z(i),num2str(i)), end
% Create and plot a periodic spline (space curve) through the data points
n = length(x);
t = 0:n-1;
ppx = csape(t,x,'periodic');
ppy = csape(t,y,'periodic');
ppz = csape(t,z,'periodic');
fxc = @(t) fnval(ppx,t);
fyc = @(t) fnval(ppy,t);
fzc = @(t) fnval(ppz,t);
fplot3(fxc,fyc,fzc,[0 n-1],'b','LineWidth',3)
% Create and plot a parametric surface based on the spline
fxs = @(s,t) s.*fxc(t);
fys = @(s,t) s.*fyc(t);
fzs = @(s,t) s.*fzc(t);
fsurf(fxs,fys,fzs,[0 1 0 n-1])
legend('Data points','Space curve (spline)','Surface')

 채택된 답변

Henning Søgaard
Henning Søgaard 2024년 3월 11일

0 개 추천

I solved the problem myself by adding the following code:
% Give surface some thickness and convert to stl-file
% (The solid surface is built from the space curve)
% (surf2solid was downloaded from https://se.mathworks.com/matlabcentral/fileexchange/30709-surf2solid)
t = (0:1/4:n-1)';
X = [0; fxc(t)]; % X-coordinates: zero and space curve x-coords.
Y = [0; fyc(t)]; % Y-coordinates: zero and space curve y-coords.
Z = [0; fzc(t)]; % Z-coordinates: zero and space curve z-coords.
V = [X Y Z]; % Vertices for surface triangles
n = height(V);
F = [ones(n-2,1) (2:n-1)' (3:n)']; % Triangle faces (row indices within V)
FV.faces = F; FV.vertices = V;
[F,V] = surf2solid(FV,'thickness',1); axis image; camlight;
tr = triangulation(F,V);
stlwrite(tr,'temp.stl');

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by