Identify triangular faces of a mesh

11 views (last 30 days)
Hi! How can I identify the faces highlighted in red within the "faces_part" matrix?
nodes_part = importdata("nodes_part.mat");
faces_part = importdata("faces_part.mat");
figure
plot3(nodes_part(:,1),nodes_part(:,2),nodes_part(:,3),'b.','Markersize',5)
trimesh(faces_part(:,:),nodes_part(:,1),nodes_part(:,2),nodes_part(:,3),'EdgeColor','b','Linewidth',1,'Facecolor','w')
grid on
xlabel('x')
ylabel('y')
zlabel('z')
view([15,50,30])
axis equal
  2 Comments
Rajeev
Rajeev on 24 Feb 2023
For highlighting the mentioned faces, their indices will be needed. Are you trying to highlight top n faces with the largest areas here?
Alberto Acri
Alberto Acri on 24 Feb 2023
In what sense their indices? Possibly one could identify red areas based on the area of the individual triangle (e.g. area_T>3)

Sign in to comment.

Accepted Answer

Rajeev
Rajeev on 24 Feb 2023
To highlight the triangle with areas greater than, let's say 'k', we need to first compute all the areas of the triangles given by the 'faces_part' array using the cross product formula.
Logical indexing can be used to find the indices of all the triangles having area greater than 'k'.
These returned indices 'idx' can then be passed to the 'trimesh' function to plot the filtered triangles from the 'nodes_part' coordinates.
I have modified the code that was provided by you to include the required changes. Note that the value of 'k' in the code is 1.
k = 1;
nodes_part = importdata("nodes_part.mat");
faces_part = importdata("faces_part.mat");
figure
% plotting all the data points
plot3(nodes_part(:,1),nodes_part(:,2),nodes_part(:,3),'b.','Markersize',5)
% forming the triangles using faces_part
trimesh(faces_part(:,:),nodes_part(:,1),nodes_part(:,2),nodes_part(:,3),'EdgeColor','b','Linewidth',1,'Facecolor','w')
hold on
% Initialize a vector to store the areas of each triangle
areas = zeros(size(faces_part, 1), 1);
% Compute the area of each triangle
for i = 1:size(faces_part, 1)
% Extract the three vertices of the current triangle
v1 = nodes_part(faces_part(i, 1), :);
v2 = nodes_part(faces_part(i, 2), :);
v3 = nodes_part(faces_part(i, 3), :);
% Compute the area of the triangle using the cross product
areas(i) = 0.5 * norm(cross(v2-v1, v3-v1));
end
% Find the indices of triangles with area greater than 3
idx = find(areas > k);
% Colouring all the trianlges with area greater than 1 (k) to red
trimesh(faces_part(idx,:),nodes_part(:,1),nodes_part(:,2),nodes_part(:,3),'EdgeColor','b','Linewidth',1,'Facecolor','r')
% formatting the plot
grid on
xlabel('x')
ylabel('y')
zlabel('z')
view([15,50,30])
axis equal
  1 Comment
Alberto Acri
Alberto Acri on 24 Feb 2023
The code you provided is perfectly fine.
May I also ask if you know how I can remove the red triangular faces from the mesh ?

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!