Identify triangular faces of a mesh
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alberto Acri
el 23 de Feb. de 2023
Comentada: Alberto Acri
el 24 de Feb. de 2023
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 comentarios
Rajeev
el 24 de Feb. de 2023
For highlighting the mentioned faces, their indices will be needed. Are you trying to highlight top n faces with the largest areas here?
Respuesta aceptada
Rajeev
el 24 de Feb. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!