does two polygons interest or not?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Steven Lord
2022-1-6
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 个评论
更多回答(1 个)
DGM
2022-1-6
编辑:DGM
2022-1-6
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 个评论
DGM
2022-1-6
编辑:DGM
2022-1-6
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Elementary Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!