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

22 visualizzazioni (ultimi 30 giorni)
I want to generate some solid models for 3D Printing. And the stl file is needed.

Risposte (2)

KSSV
KSSV il 18 Nov 2016
  1 Commento
DGM
DGM il 28 Set 2025
Modificato: DGM il 7 Ott 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.

Accedi per commentare.


David
David il 14 Set 2022
Modificato: David il 14 Set 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 Commento
DGM
DGM il 30 Lug 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

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by