Extract a set of polygons

9 views (last 30 days)
Andrei-Florin
Andrei-Florin on 6 Jul 2022
Commented: Johan on 6 Jul 2022
Based of a concave polygon witch has as input his vertices , I obstain the sectors that partition that poligon in convex pieces, so after that i have the coodinates of start and end points of the segment lines that do the partition.
My problem is that I need to identify each of this pieces and store them based of their vertices
This is the plot , Vx=[210 450 390 300 360 270 270 360 285 225 285 240 195 90 120 15 60 120 90 45 45 15 120 150 150];
Vy=[90 195 240 195 180 180 195 255 360 300 315 180 300 240 315 225 120 195 90 90 45 15 60 30 225]; are the vertices of the main polygon, and those are stard and end point coordinates of those segments
ex = 120.0000 395.4545 240.0000 270.0000 312.2727 210.0000 24.5902 197.8723 45.0000 150.0000
ey = 60.0000 171.1364 180.0000 270.0000 321.8182 90.0000 202.6230 292.3404 27.8571 232.5000
sx = 90 360 270 270 285 240 90 120 45 150
sy = 90 180 180 195 315 180 240 195 45 225
  1 Comment
Johan
Johan on 6 Jul 2022
You could try to do it with polyshape by giving a finite width to your segment. Here is an example below, still need a bit of work though.
Vx=[210 450 390 300 360 270 270 360 285 225 285 240 195 90 120 15 60 120 90 45 45 15 120 150 150];
Vy=[90 195 240 195 180 180 195 255 360 300 315 180 300 240 315 225 120 195 90 90 45 15 60 30 225];
ex = [120.0000 395.4545 240.0000 270.0000 312.2727 210.0000 24.5902 197.8723 45.0000 150.0000];
ey = [60.0000 171.1364 180.0000 270.0000 321.8182 90.0000 202.6230 292.3404 27.8571 232.5000];
sx = [90 360 270 270 285 240 90 120 45 150];
sy = [90 180 180 195 315 180 240 195 45 225];
%Convert vertices to polyshape
myshape = polyshape(Vx,Vy);
%Initialize arrays for the loop
mysubshape = myshape;
mypieces = polyshape();
for i_seg = 1:length(sx)
mysegment = [sx(i_seg),ex(i_seg);sy(i_seg),ey(i_seg)];
%Create segment of 0.1 width
mypolysegement = polyshape([mysegment(1,:),mysegment(1,:)+0.1],[mysegment(2,:),mysegment(2,:)+0.1]);
%subtract segment from mysubshape, this should lead to at least 2
%polygon. The polygons are individualised by the regions() function
temp = regions(subtract(mysubshape,mypolysegement));
%The largest polygon is the remaining shape the other are the pieces
%exept for the last segment
Area_pieces = area(temp);
mysubshape = temp(Area_pieces == max(Area_pieces));
if i_seg < length(sx)
mypieces = [mypieces; temp(Area_pieces < max(Area_pieces))];
else
mypieces = [mypieces; temp];
end
end
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
%Result is not perfect, some pieces are not separated properly
figure(1)
clf
hold on
plot(myshape)
plot(mypieces)
hold off
axis equal

Sign in to comment.

Answers (0)

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!