How can I plot a 3D solid figure (not just 3d surface)

23 visualizaciones (últimos 30 días)
lingfeng zhou
lingfeng zhou el 18 de Nov. de 2016
Editada: DGM el 7 de Oct. de 2025
I want to generate some solid models for 3D Printing. And the stl file is needed.

Respuestas (2)

KSSV
KSSV el 18 de Nov. de 2016
  1 comentario
DGM
DGM el 28 de Sept. de 2025
Editada: DGM el 7 de Oct. de 2025
Since R2018b, MATLAB has built-in STL tools
For legacy versions needing third-party tools, I'd recommend these tools over #22409. This explains why.
If you use #22409 or #20922 in a modern installation, you will shadow the inbuilt tools and likely cause problems for yourself unless you rename them.

Iniciar sesión para comentar.


David
David el 14 de Sept. de 2022
Editada: David el 14 de Sept. de 2022
n = 30;
[X,Y] = meshgrid(linspace(0,1,2*n+1));
L = (40/51/0.9)*membrane(1,n);
figure, subplot(2,2,[1 3]), title 'Thin surface'
surf(X,Y,L,'EdgeColor','none'); colormap pink; axis image; camlight
subplot(2,2,2), title 'Block elevation'
[f,v] = surf2solid(X,Y,L,'elevation',min(L(:))-0.05); axis image; camlight; camlight
fv_block = struct('faces',f,'vertices',v);
subplot(2,2,4), title 'Thickness'
surf2solid(X,Y,L,'thickness',-0.1); axis image; camlight;
stlwriteSven('test.stl',fv_block)
  1 comentario
DGM
DGM el 30 de Jul. de 2025
I know that's just mostly derived from the surf2solid() synopsis, but this usage does not strictly depend on the behavior of #20922. It can be done with the built-in stlwrite. The hazard in recommending #20922 is that most readers now already have an encoder by the same name and won't know that they will cause naming conflicts when they download it.
To clean the example up:
% some data
n = 30;
[X,Y] = meshgrid(linspace(0,1,2*n+1));
L = (40/51/0.9)*membrane(1,n);
% surf() resets the axes and deletes descendant objects,
% so the title can't be drawn first without extra work.
% at first i thought this was something that would have worked pre-R2013b,
% but no, it's just a mistake in the synopsis.
figure(1); surf(X,Y,L,'EdgeColor','none');
axis equal; camlight; title('Thin surface')
% lofting a solid block from a fixed elevation
figure(2); title('Block elevation')
[F V] = surf2solid(X,Y,L,'elevation',min(L(:))-0.05);
% write it
%stlWrite('test1.stl',F,V) % FEX #51200 or #20922 in R2018a or older
stlwrite(triangulation(F,V),'test1.stl') % in R2018b or newer
patch('faces',F,'vertices',V,'facecolor','w','edgecolor','none');
view(3); camlight; axis equal; grid on
% normal offset by a given distance
figure(3); title('Thickness')
[F V] = surf2solid(X,Y,L,'thickness',-0.1);
% write it
%stlWrite('test2.stl',F,V) % FEX #51200 or #20922 in R2018a or older
stlwrite(triangulation(F,V),'test2.stl') % in R2018b or newer
patch('faces',F,'vertices',V,'facecolor','w','edgecolor','none');
view(3); camlight; axis equal; grid on

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by