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

16 ビュー (過去 30 日間)
lingfeng zhou
lingfeng zhou 2016 年 11 月 18 日
編集済み: DGM 2025 年 10 月 7 日
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 Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by