Generating STL from vertices and thickness?

조회 수: 6 (최근 30일)
N/A
N/A 2017년 10월 23일
답변: DGM 2025년 4월 3일
I want to generate a .stl file of the shape shown in the image. I define the shape using a set of vertices, which define a 2d polygon, and a thickness which makes it 3d. I have tried a few methods but haven't had any success in generating .stl file similar to the one I need.

답변 (2개)

KSSV
KSSV 2017년 10월 23일
If you have vertices and nodal connectivity matrix in hand, use this to write to .stl file. https://in.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-filename--varargin-

DGM
DGM 2025년 4월 3일
If you have the boundary vertices of one of the profiled sides, the rest is relatively simple. For such a simple part, it's easy enough to manually triangulate the surface, or you can use delaunayTriangulation().
% you have some vertices defined in a CCW path around the object boundary
V = [0 0 0; 1 0 0; 1 2 0; 6 2 0; 11 0 0; 11 1 0; 6 3 0; 1 3 0; 1 5 0; 0 5 0];
th = 0.4; % and you have some thickness
% either you can just manually define the triangles on the top side ...
%F = [1 2 3; 4 5 6; 1 3 10; 3 8 10; 8 9 10; 8 3 4; 8 4 7; 4 6 7];
% ... or you could do a constrained triangulation to generate them.
nverts = size(V,1);
E = [1:nverts; circshift(1:nverts,-1)].';
T = delaunayTriangulation(V(:,1:2),E);
F = T.ConnectivityList(isInterior(T),:);
% create the back side faces and vertices
nverts = size(V,1);
V = [V; V]; % duplicate (x and y stay the same)
V(1:nverts,3) = th; % establish z-offset between the two sets of faces
F = [F; fliplr(F) + nverts]; % flip the winding and offset the indices
% since our object is two parallel surfaces with the same number of
% boundary vertices (in the same order), we can just stitch those together.
% va is just a right-handed progression of the boundary vertices (in a column vector).
% in this case, our boundary vertex list is a simple linear sequence.
va = reshape(1:nverts,[],1); % 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')
See also:
Another simple example:
A more complicated case with multiple boundaries, still using the same idea:

카테고리

Help CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by