Identify triangular faces of a mesh
3 ビュー (過去 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
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?
採用された回答
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!