Identify triangular faces of a mesh

4 次查看(过去 30 天)
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 个评论
Rajeev
Rajeev 2023-2-24
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 2023-2-24
In what sense their indices? Possibly one could identify red areas based on the area of the individual triangle (e.g. area_T>3)

请先登录,再进行评论。

采纳的回答

Rajeev
Rajeev 2023-2-24
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 个评论
Alberto Acri
Alberto Acri 2023-2-24
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 ?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by