does two polygons interest or not?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
CHANDRABHAN Singh
le 6 Jan 2022
Réponse apportée : Steven Lord
le 6 Jan 2022
Let's say
these are two non interscting ploygons (shown below). How can i get a logical relationship out of this. Something like, if the polygons intersect or touch
paramter = true;
otherwise
parameter = false;
x1 =[-2.6967 -2.0891 -0.0846 1.5544 2.6872 -2.6967];
x2 = [5.6494 6.6386 6.6898 4.0313 1.3002 1.9802 5.6494];
y1 = [ 0.1340 -1.7104 -2.6987 -2.2076 -0.2624 0.1340];
y2 = [1.8624 3.4274 4.2346 6.6998 3.9686 2.2082 1.8624];
plot(x1,y1,x2,y2);
grid on;
poly1 = polyshape(x1',y1');
poly2 = polyshape(x2',y2');
polyout = intersect(poly1,poly2);
0 commentaires
Réponse acceptée
Steven Lord
le 6 Jan 2022
You may be able to use the approach from this blog post that determines if two states (represented as polyshape objects) share a border.
0 commentaires
Plus de réponses (1)
DGM
le 6 Jan 2022
Modifié(e) : DGM
le 6 Jan 2022
You could test for an overlap using the intersection you calculated:
x1 = [0 1 1 0 0];
y1 = [0 0 1 1 0];
x2 = [1 2 2 1 1]-0.2;
y2 = [1 1 2 2 1]-0.2;
plot(x1,y1,x2,y2);
grid on;
poly1 = polyshape(x1',y1');
poly2 = polyshape(x2',y2');
polyout = intersect(poly1,poly2);
theyintersect = polyout.NumRegions~=0 % returns a logical scalar
Although that won't return true if they are merely tangent.
x1 = [0 1 1 0 0];
y1 = [0 0 1 1 0];
x2 = [1 2 2 1 1];
y2 = [1 1 2 2 1]-0.2;
plot(x1,y1,x2,y2);
grid on;
poly1 = polyshape(x1',y1');
poly2 = polyshape(x2',y2');
polyout = intersect(poly1,poly2);
theyintersect = polyout.NumRegions~=0
2 commentaires
DGM
le 6 Jan 2022
Modifié(e) : DGM
le 6 Jan 2022
From the webdocs:
The NumRegions property is described as:
Number of regions making up the polygon, specified as a scalar integer. A region is an area bounded by an outer boundary, which may contain hole boundaries that lie entirely inside the outer boundary.
So a simple polyshape (e.g. a square) would have one region. If a polyshape intersects itself (e.g. a bowtie), it might have more than one region. If a polyshape encloses zero area, it has zero regions.
As a trivial polyshape has zero vertices, you could alternatively check to see if the vertex list is empty.
theyintersect = numel(poly1.Vertices)~=0
I just chose to use NumRegions instead.
Voir également
Catégories
En savoir plus sur Elementary Polygons dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!