Clear Filters
Clear Filters

Triangle clustering of .stl file

25 views (last 30 days)
Lorenzo Pollicini
Lorenzo Pollicini on 17 Apr 2024
Answered: Aastha on 1 Oct 2024 at 3:37
Hello everyone,
I am asking help to the MATLAB community since my head is burning :(
So I have stored two matrices F(mx3) and N(ux3), where u is 3 times m. The first matrix F contains the triangles of an .stl file, namely it containes, in each row, the indices of the rows of matrix N where the X, Y, and Z coordinate are stored. So, for example, if F(1,:) = [1 2 3], it means that the coordinates of the vertices of the first triangle have to be found in rows 1,2, and 3 of matrix N.
Plotting the triangles we have this situation:
Now what i want to do is divide the triangles in different regions (in this case 3, but the number of regions should not be a user input).
I have been able to identify the triangles wich lies on the border writing a small algorithm that search, for each triangle, what are the adjacent triangles (looking for the common edges). All the triangles that only have 1 or 2 adjacent triangles are stored as "Border Triangles".
Here, unfortunately, is where i stop. I have thought to use some graph traversal methods to identify the regions but i am not familiar with this type of techniques.
Any suggestions?
I am not attaching any dataset since it will be to heavy and probably to much confusing.
Hoping to find an answer here :)
Thanks

Answers (1)

Aastha
Aastha on 1 Oct 2024 at 3:37
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!

Community Treasure Hunt

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

Start Hunting!