필터 지우기
필터 지우기

Split two 3D geometries having the same matrix of nodes and faces

조회 수: 35 (최근 30일)
Alberto Acri
Alberto Acri 2024년 5월 20일 12:43
답변: Malay Agarwal 2024년 5월 21일 9:22
I have a matrix containing the nodes and a matrix containing the triangular faces of two 3D geometries as shown below:
Is there any way to split the two geometries? Then extract only nodes/triangles of the geometry in the yellow box?
file_im = importdata("f_mm.mat");
nodes_e = file_im.nodes_e;
faces_e = file_im.faces_e;
g_P_sez = file_im.g_P_sez;
figure
trimesh(faces_e(:,:),nodes_e(:,1),nodes_e(:,2),nodes_e(:,3),'EdgeColor','k','Linewidth',0.1,'Facecolor',[255 0 0]/255,'FaceAlpha',1)
hold on
plot3(g_P_sez(:,1),g_P_sez(:,2),g_P_sez(:,3),'k.','Markersize',15)
hold off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')

채택된 답변

Malay Agarwal
Malay Agarwal 2024년 5월 21일 9:22
I understand that you have a single set of nodes and faces which defines two geometries and want to separate the two geometries.
You can achieve this by computing the connected components of the triangulation of the geometry. Since the two geometries are disconnected, you will obtain a distinct connected component for each geometry. You can then extract the nodes and faces from the two connected components.
MATLAB has the built-in function “conncomp” to compute connected components. Please try the following code:
file_im = importdata("f_mm.mat");
nodes_e = file_im.nodes_e;
faces_e = file_im.faces_e;
g_P_sez = file_im.g_P_sez;
% Create a triangulation using the faces and nodes
triangle = triangulation(faces_e, nodes_e);
% Obtain the edges of the triangulation
s = triangle.ConnectivityList(:, [1 2]);
t = triangle.ConnectivityList(:, [2 3]);
% Create a graph and obtain its connected components
G = graph(s(:), t(:));
I = G.conncomp;
u = unique(I);
P = triangle.Points;
T = triangle.ConnectivityList;
clear Obj
% Create a triangulation out of each connected component
for i=1:length(u)
j = find(I == i);
Pi = P(j, :);
[b, Ti] = ismember(T, j);
Ti = Ti(all(b, 2), :);
Obj{i} = triangulation(Ti, Pi);
end
figure();
subplot(2, 2, [1 2]);
trimesh(triangle);
% Plot the triangulation
for i=1:length(Obj)
subplot(2, 2, i+2);
trimesh(Obj{i});
end
The code above:
  • Creates a triangulation from the geometry using the “triangulation” function.
  • Converts the triangulation into an undirected graph and computes the connected components of the graph using “conncomp”.
  • Extracts the nodes and faces for each connected component and creates a separate triangulation for each.
  • Plots each triangulation using the “subplot” function.
Please refer to the following resources for further information:
Hope this helps!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by