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

16 次查看(过去 30 天)
I want to generate some solid models for 3D Printing. And the stl file is needed.

回答(2 个)

KSSV
KSSV 2016-11-18
  1 个评论
DGM
DGM 2025-9-28
编辑:DGM 2025-10-7
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.

请先登录,再进行评论。


David
David 2022-9-14
编辑:David 2022-9-14
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 个评论
DGM
DGM 2025-7-30
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by