Using matlab to generate complex graphics stl file

5 ビュー (過去 30 日間)
Chenglin Li
Chenglin Li 2023 年 1 月 9 日
編集済み: DGM 2025 年 4 月 2 日
Hi, I have been able to use matlab to generate cuboid stl files, but the stl files of concave bodies always make mistakes, because there are always problems in the triangle division of concave surface. Could you please tell me how to automatically divide triangles that can generate stl files on concave surface.I would really appreciate it if you could help me.
The generated cuboid stl file
The graph you want to generate

採用された回答

DGM
DGM 2025 年 4 月 2 日
編集済み: DGM 2025 年 4 月 2 日
For a simple "sandwich" model composed of two roughly flat and parallell profiled sides connected by a ribbon around their boundary, it's easy enough if you can triangulate one of the flat sides.
% some parameters
d = [4 1 2]; % block dimensions [x y z]
s = [1 1]; % slot dimensions [x z]
os = 1; % slot offset on x
% vertices and faces for the front side
V = [0 0 0; d(1) 0 0; d(1) 0 d(3); s(1)+os 0 d(3); ...
s(1)+os 0 d(3)-s(2); os 0 d(3)-s(2); os 0 d(3); 0 0 d(3)];
F = [6 7 8; 1 6 8; 1 2 6; 6 2 5; 2 3 5; 3 4 5];
% create the back side faces and vertices
nverts = size(V,1);
V = [V; V]; % duplicate (x and z stay the same)
V(nverts+1:end,2) = d(2); % offset y
F = [F; fliplr(F) + nverts]; % flip the winding and offset the indices
% since our object is two parallel faces with the same number of
% boundary vertices, we can just stitch those together (lofting).
% our boundary vertex list is simply sequential
va = (1:nverts).'; % front
vb = va + nverts; % back
vc = circshift(va,-1); % front
vd = vc + nverts; % back
F = [F; va vb vc; vd vc vb]; % add them to the list
% write to file
stlwrite(triangulation(F,V),'testfile.stl')
% display it using patch()
patch('faces',F,'vertices',V, ...
'facecolor','w','edgecolor','k');
view(3); camlight; view(10,33)
axis equal; grid on
xlabel('X'); ylabel('Y'); zlabel('Z')
If you're asking how to do CSG on an existing model, that's something else.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSTL (STereoLithography) についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by