does two polygons interest or not?

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);

 采纳的回答

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 个)

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 个评论

@DGM can you please give me some idea what exactly is "polyout.NumRegions"? And thank you for your kind supoort.
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.

请先登录,再进行评论。

类别

帮助中心File 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