필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Alberto Acri
Alberto Acri 2023년 10월 5일
댓글: Alberto Acri 2023년 10월 9일
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에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by