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 CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by