does two polygons interest or not?

4 ビュー (過去 30 日間)
CHANDRABHAN Singh
CHANDRABHAN Singh 2022 年 1 月 6 日
回答済み: Steven Lord 2022 年 1 月 6 日
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);

採用された回答

Steven Lord
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.

その他の回答 (1 件)

DGM
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
theyintersect = logical
1
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
theyintersect = logical
0
  2 件のコメント
CHANDRABHAN Singh
CHANDRABHAN Singh 2022 年 1 月 6 日
編集済み: CHANDRABHAN Singh 2022 年 1 月 6 日
@DGM can you please give me some idea what exactly is "polyout.NumRegions"? And thank you for your kind supoort.
DGM
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 ExchangeElementary Polygons についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by