Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
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;
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
hold off
axis equal

Akzeptierte Antwort

Malay Agarwal
Malay Agarwal am 21 Mai 2024
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);
subplot(2, 2, [1 2]);
% Plot the triangulation
for i=1:length(Obj)
subplot(2, 2, i+2);
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!

Weitere Antworten (0)




Community Treasure Hunt

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

Start Hunting!

Translated by