Over 1000 faces when importing stl file to matlab
4 views (last 30 days)
Show older comments
hello, ive prepared a simple crater shape object (after creating it in autocad i rescaled it using mattercontrol slicer software), and exported it to matlab. when i look at the object properties (in matlab) it has about 1800 faces , 2700 edges and 900 vertices, which make it impossible to work with. i only need one face and one edge.
is there anything i can do in matlab to fix this? thanks
2 Comments
DGM
on 3 Apr 2025
It's not possible to create any valid surface geometry with one face with one edge. A triangle has three edges.
Walter Roberson
on 3 Apr 2025
At the very least there would have to be one face for the outside boundary. But if that is the only face, then the result would be a flat surface, contrary to the fact that it is intended to be a "crater shape". We have a contradiction, so asking for only one face is unreasonable.
Answers (1)
DGM
on 4 Apr 2025
I thought about this one, and maybe there's an answer. Maybe we're not talking about "faces" as in getting individual triangles or quads, but isolating surface regions of an object. Something like this:
unzip minbasesaddle.stl.zip % needed for the forum
% a 30x30 lofted surface with minimal base layer geometry
% this compares well to the described properties
% 904 vertices
% 1804 faces
% 2706 edges
T = stlread('minbasesaddle.stl');
% display it using patch()
patch('faces',T.ConnectivityList,'vertices',T.Points, ...
'facecolor','w','edgecolor','k');
view(3); camlight; view(10,33)
axis equal; grid on
xlabel('X'); ylabel('Y'); zlabel('Z')
% get only the top surface
V = T.Points;
F = T.ConnectivityList;
goodverts = V(:,3) > 0.1;
[F V] = prunebadverts(F,V,goodverts);
% display it using patch()
figure
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')
function [F V] = prunebadverts(F,V,goodverts)
% Given a mask specifying which vertices are good,
% discard bad vertices and all faces which reference them.
% If no mask is given, get rid of vertices with NaN z-value.
% Remap face indices when done
if nargin == 2
goodverts = find(~isnan(V(:,3)));
else
goodverts = find(goodverts);
end
goodfaces = all(ismember(F,goodverts),2);
F = F(goodfaces,:); % get rid of junk faces
map = zeros(size(V,1),1); % remap vertex indices
map(goodverts) = 1:numel(goodverts);
V = V(goodverts,:); % get rid of junk vertices
F = map(F); % remap faces to match new vertex list
end
That said, even if we're talking about this as a region, it still has four "edges". Maybe OP had something cylindrical?
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
