delete the top and bottom triangular faces of the 3D object
9 views (last 30 days)
Show older comments
Alberto Acri
on 5 Oct 2023
Commented: Alberto Acri
on 9 Oct 2023
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
0 Comments
Accepted Answer
Fabio Freschi
on 5 Oct 2023
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 Comments
Fabio Freschi
on 9 Oct 2023
% 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),:) = [];
More Answers (0)
See Also
Categories
Find more on Spatial Search in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!