How to post-process output data of SurfaceIntersection function???

5 visualizaciones (últimos 30 días)
Faez Alkadi
Faez Alkadi el 2 de Nov. de 2017
Editada: Faez Alkadi el 19 de Oct. de 2022
Still looking for answer:
In the example Surface/Surface Intersection of the function SurfaceIntersection by Jaroslaw Tuszynski to find intersection between two objects( #2 and #3).
% Create Surface#1
[x,y] = pol2cart((0:2)'*2*pi/3,40);
Surface1.vertices = [0 0 110; x y [0; 0; 0]];
Surface1.faces = [1 2 3; 1 3 4; 1 4 2; 2 3 4];
%Create Surface #2
load tetmesh;
TR = triangulation(tet,X);
[Surface2.faces, Surface2.vertices] = freeBoundary(TR);
% Create Surface #3
Surface3.vertices = [x y [30; 30; 30]; y x [60; 60; 60]];
Surface3.faces = [1:3;4:6];
% Plot them
clf; hold on
%S=Surface1; trisurf(S.faces, S.vertices(:,1),S.vertices(:,2),S.vertices(:,3),'FaceAlpha', 0.5, 'FaceColor', 'r');
S=Surface2; trisurf(S.faces, S.vertices(:,1),S.vertices(:,2),S.vertices(:,3),'FaceAlpha', 0.5, 'FaceColor', 'g');
S=Surface3; trisurf(S.faces, S.vertices(:,1),S.vertices(:,2),S.vertices(:,3),'FaceAlpha', 0.5, 'FaceColor', 'b');
view([3 1 1])
axis equal
title ('Three test surfaces')
legend({'#2', '#3'});
%[intersect12, Surf12] = SurfaceIntersection(Surface1, Surface2);
%[intersect13, Surf13] = SurfaceIntersection(Surface1, Surface3);
[intersect23, Surf23] = SurfaceIntersection(Surface3, Surface2);
clf; hold on
%S=Surf12; trisurf(S.faces, S.vertices(:,1),S.vertices(:,2),S.vertices(:,3),'EdgeColor', 'r', 'FaceColor', 'r');
%S=Surf13; trisurf(S.faces, S.vertices(:,1),S.vertices(:,2),S.vertices(:,3),'EdgeColor', 'g', 'FaceColor', 'g');
S=Surf23; trisurf(S.faces, S.vertices(:,1),S.vertices(:,2),S.vertices(:,3),'EdgeColor', 'b', 'FaceColor', 'b');
title ('Surface/Surface intersections')
legend({'#2/#3'});
view([3 1 1])
axis equal
zlim([0 80])
The result Surf23.edges is (60x2 double) array, every row represents the ID# of points that make the edge of intersection Surface#2 and Surface#3. These edges (blue lines) look like 5 separate continuous groups in the plot, which represents the free boundary of the legs of Surface#2. as shown in the pictures attached.
What I'm wishing for is to post process the data points of these 5 lines(continuous polygons of edges) and store it in a (C= 5x1 cell) array. each line (continuous polygons of edges) is (Nx3 double) inside the C array? Sorted from beginning to end in one direction (CW or CCW)
In other words, how can I get every group of continuous polygon in a separate (Nx3 double) array.Sorted from beginning to end in one direction (CW or CCW)?
And in general, if there was more than 5 continuous lines (continuous polygons of edges), is it possible to have every continuous line in a separate double array Nx3 ,as long as they are connected through a vertex, ? and these double arrays will be inside Cell array=Mx1, where M=Number of lines (continuous polygons)??
Help would be appreciated.
Thank you so much.
  3 comentarios
Faez Alkadi
Faez Alkadi el 9 de Nov. de 2017
Editada: Faez Alkadi el 9 de Nov. de 2017
The data I need to sort is Surf23.edges(((ATTACHED)). This data represents the ID# of points in Surf23.vertices which makes an edge of intersection. I want every connected edge to be in a separate Nx3 double array, sorted Clock-wise or Anti-CW with respect to XY axes.
Thank you so much.
Faez Alkadi
Faez Alkadi el 19 de Dic. de 2018
Editada: Faez Alkadi el 19 de Dic. de 2018
Hello KSSV;
If you can please help to sort this lines properly.
I needed to intersect a cube with hole inside as shown with Red color in pictures with flat surface as shown in Yellow. The function worked fine and i got the intersection as shown in blue lines. The Blue are not sorted in CCW or CCW. It is sorted randomly.
So What I wanted is to save every line in one seperate double matrix (XYZ) . So I wrote the following code to save them in Cell called Line_Sorted_all, this Cell is supossed to be (2x1 cell) because I have 2 Lines. But instead i got (5x1 cell) according to my code.
In my code I depend S.edges. I don't know what is wrong with my code. Hope you can help.
S1 and S2 are the surfaces. S is the result of intersection.
Following is the result of the intersection:
Following is the result of my code:
%% plot the intersectiom
trisurf(S.faces, S.vertices(:,1),S.vertices(:,2),S.vertices(:,3),'EdgeColor', 'b', 'FaceColor', 'b');
xlabel('X')
ylabel('Y')
zlabel('Z')
hold on
%%
%S is the result of Surface/Surface intersection
C={}; %Index of data points in S.edges.
Line_Sorted_all={};% Original data points.
% length_of_data=2;
Num_Of_Lines = 0;% To counts # of loops and find # of continuous lines
rest_of_data=1; %means its not empty yet !!!line
while (rest_of_data==1)
Num_Of_Lines = Num_Of_Lines + 1;
S1=[S.edges(1,:)];%To starts from the first row in Surf23.edges
for i=2:length(S.edges)
[row,col,v]=find(S.edges(:,1)==S1(end,end));
S1=[S1;S.edges(row,:)];
end
%ordered=[ordered;ordered(end,:)];
for i=2:length(S.edges)
[row,col,v]=find(S.edges(:,2)==S1(end,end));
B= fliplr(S.edges(row,:));
S1=[S1;B];
end
S2=unique(S1,'stable');
C{Num_Of_Lines,1}=S2;
flag = ~ismember(S.edges,S1);
index = find(flag(:,1));
edges1=S.edges(:,1);
edges2=S.edges(:,2);
S.edges=[edges1(index),edges2(index)];
rest_of_data =~isempty(S.edges);
x=S.vertices(:,1);
y=S.vertices(:,2);
z=S.vertices(:,3);
xyz=[x(S2),y(S2),z(S2)];
Line_Sorted_all{Num_Of_Lines,1}=xyz;
plot3(xyz(:,1),xyz(:,2),xyz(:,3),'linewidth',10)
hold on
xlabel('X')
ylabel('Y')
zlabel('Z')
view(45,45)
end

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by