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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1304440/image.png)
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!