Hi Lorenzo Pollicini,
As I understand, you'd like to automatically cluster the triangles in a .stl file without user input. To achieve this, you can convert the STL triangles into a point cloud by retaining only the centroids of each triangle in the STL file.
This can be done using the following MATLAB code:
% Assuming F is an mx3 matrix and N is a ux3 matrix where u = 3*m
% Initialize the matrix to store the centroids
m = size(F, 1); % Number of triangles
centroids = zeros(m, 3);
% Loop through each triangle defined in F
for i = 1:m
indices = F(i, :); % Row of F that contains indices
vertices = N(indices, :); % Get the corresponding coordinates from N
centroids(i, :) = mean(vertices, 1); % Compute the mean of the vertices
end
% 'centroids' now contains the centroids of each triangle
Once you have the point representation of the STL triangles, you can experiment with the clustering methods available in MATLAB to cluster the triangles.
You may refer to the MathWorks documentation for more information on clustering using the following link:
After forming clusters using these point representations, you can uniquely map the points back to their respective triangles, thereby clustering the triangles.
I hope this helps!