delete the top and bottom triangular faces of the 3D object

7 次查看(过去 30 天)
Hi! Is there a way to delete the top and bottom triangular faces of the tube?
nodes = importdata("NODES.mat");
faces = importdata("FACES.mat");
figure
plot3(nodes(:,1),nodes(:,2),nodes(:,3),'k.','Markersize',2);
hold on
trimesh(faces(:,:),nodes(:,1),nodes(:,2),nodes(:,3),'EdgeColor','k','Linewidth',0.1,'Facecolor','b','FaceAlpha',1)
hold off
axis equal

采纳的回答

Fabio Freschi
Fabio Freschi 2023-10-5
By looking at your data I see that the top and bottom triangles have a predominant z direction of the face normals. So I play with this
% your code
nodes = importdata("NODES.mat");
faces = importdata("FACES.mat");
figure
plot3(nodes(:,1),nodes(:,2),nodes(:,3),'k.','Markersize',2);
hold on
trimesh(faces(:,:),nodes(:,1),nodes(:,2),nodes(:,3),'EdgeColor','k','Linewidth',0.1,'Facecolor','b','FaceAlpha',1)
hold off
axis equal
% create triangulation object to easily calculate face normals
TR = triangulation(faces,nodes);
P = incenter(TR);
F = faceNormal(TR);
% plot on the previous plot to see what's happening
hold on
quiver3(P(:,1),P(:,2),P(:,3), ...
F(:,1),F(:,2),F(:,3),0.5,'color','r');
% dot product with z directed unit vector
proj = F*[0 0 1].';
% threshold (play with this value)
idx = abs(proj) > 0.6;
% remove faces
faces(idx,:) = [];
% new plot without faces
figure
trimesh(faces(:,:),nodes(:,1),nodes(:,2),nodes(:,3),'EdgeColor','k','Linewidth',0.1,'Facecolor','b','FaceAlpha',1)
Hope it helps
  13 个评论
Fabio Freschi
Fabio Freschi 2023-10-9
% find normals oriented like u1 (dot product)
idx1 = abs(F*u1.') > 0.9999;
% find normals oriented like u2 (dot product)
idx2 = abs(F*u2.') > 0.9999;
% find barycenters laying on the magenta plane
ipln1 = abs(sum(P.*u1,2)-sum(u1.*P1,2)) < 0.001;
% find barycenters laying on the magenta plane
ipln2 = abs(sum(P.*u2,2)-sum(u2.*P2,2)) < 0.001;
% remove bottom lid
faces((idx1 & ipln1) | (idx2 & ipln2),:) = [];

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spatial Search 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by