# How to define the areas of specific polygons?

3 Ansichten (letzte 30 Tage)
A LL am 22 Sep. 2021
Bearbeitet: A LL am 22 Sep. 2021
I am looking for a clever way to define the points of the polygons A, B, C, E, F (see attached figure 2007_zones.png) on my map.
I have several maps, and I want to find a technique that I can reuse even when the shapes of the polygons A, B, C, E, F vary.
I am working on a grid of 360x360 with x and y values from 1 to 361.
The shape in light green is an alphaShape object, and I can access all the points (x,y) forming this shape with the file shpfile.mat.
The positions of all the points in the orange contour are contained in the file startfile.mat with the position defined by (xstart,ystart).
The positions of all the points in the purple contour are contained in the file endfile.mat with the positions defined by (xend,yend).
I can define the regions A (blue) and the combined regions BCEF (red) using the inShape function of alphaShape.
-->see attached figure main_zones.fig and code below
I am now looking for a way to partition the respective regions B, C, E ,and F, and I have no clue how to proceed. Maybe using the numRegions function for the alphaShape object?
Here is my code to find the points respectively in region A (blue) and BCEF (red)
%Define polygons A and BCEF
load('startfile.mat'); %var name: SICSTART, xstart, ystart
load('endfile.mat'); %var name: SICEND, xstart, yend
%Define the index of the points that are inside shp and inside the orange contour:
%0 --> point is not in shp but in the orange contour (region BCEF)
%1 --> point is both in shp and in the orange contour
tf1 = inShape(shp,xstart,ystart);
index0 = find(tf1==0);
x0 = xstart(index0);
y0 = ystart(index0);
shpBCEF = alphaShape(x0,y0,1);
N = numRegions(shpBCEF);
index1 = find(tf1==1);
x1 = xstart(index1);
y1 = ystart(index1);
shp1 = alphaShape(x1,y1,2);
%Define the index of the points that are inside shp and inside the purple contour:
%0 --> point is not in shp but in the purple contour
%1 --> point is both in shp and in the purple contour (i.e. entire shp)
tf2 = inShape(shp,xend,yend);
index2 = find(tf2==1);
x2 = xend(index2);
y2 = yend(index2);
%Define the index of the points that are inside both shp and shp1:
%0 --> point is not in shp1 but in shp (region A)
%1 --> point is both in shp1 and in shp
tf3 = inShape(shp1,x2,y2);
index3 = find(tf3==0);
x3 = x2(index3);
y3 = y2(index3);
%Grid
x = [1:361];
y = x;
[xx,yy] = meshgrid(x,y);
%Figure
figure(1);
hold on;
axis ij;
grid on;
plot(shp,'FaceAlpha',0.2)
%plot(shpBCEF,'FaceAlpha',0.2)
%plot(shp1,'FaceAlpha',0.2)
[M1,c1] = contour(xx,yy,SICSTART,1,'LineWidth',3,'Color', [1.0000 0.5984 0.2000]);
[M2,c2] = contour(xx,yy,SICEND,1,'LineWidth',3,'Color', [0.6769 0.4447 0.7114]);
plot(x3,y3,'x'); %region A (blue)
plot(x0,y0,'x'); %region BCEF (red)
%plot(x1,y1,'x');
%plot(x2,y2,'x');
xlim([110 270]);
ylim([70 260]);
legend('shp','start','end')
Thank you
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Bounding Regions finden Sie in Help Center und File Exchange

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by