I'm trying to use RegionIntersection in a couple of Polygons. The polygons are the following:
p1=Polygon[{{-102.251, 21.8628}, {-102.252, 21.8628}, {-102.252, 21.8631}, {-102.251, 21.8631}, {-102.251, 21.8628}}]
and
p2=Polygon[{{-102.253, 21.8671}, {-102.253, 21.8682}, {-102.253, 21.8682}, {-102.253, 21.8682}, {-102.253, 21.8681}, {-102.252, 21.868}, {-102.252, 21.8678}, {-102.252, 21.8673}, {-102.253, 21.8672}, {-102.253, 21.8671}}]
When I run r = RegionIntersection[p1, p2]
I was expecting that the resulting object was a "Region", however it is something like RegionIntersection[Polygon{{...}},Polygon{{...}}]
.
When I try to compute the Area of the resulting region it gives me:
Area::reg: "RegionIntersection[Polygon[{{-102.253,21.8671},{-102.253,21.8682},{-102.253,21.8682},{-102.253,21.8682},<<3>>,{-102.252,21.8673},{-102.253,21.8672},{-102.253,21.8671}}],<<1>>] is not a correctly specified region.
And if I test for a region with RegionQ[r]
I obtain `true
Also if I try to plot the region discretizing with DiscretizeRegion[r]
I obtain:
DiscretizeRegion[RegionIntersection[Polygon[{{-102.251, 21.8628}, {-102.252, 21.8628}, {-102.252, 21.8631}, {-102.251, 21.8631}, {-102.251, 21.8628}}],Polygon[{{-102.253, 21.8671}, {-102.253, 21.8682}, {-102.253, 21.8682}, {-102.253, 21.8682}, {-102.253, 21.8681}, {-102.252, 21.868}, {-102.252, 21.8678}, {-102.252, 21.8673}, {-102.253, 21.8672}, {-102.253, 21.8671}}]]]
So it seems that the resulting object from the Intersection is a region but it is not possible to compute anything on it.
Following the examples on the Documentation I notice that using circles it behaves correctly and it is possible to compute on the intersection, however if the intersection is nothing (i.e. the two regions don't intersect) the object is still a region. I was wondering if there is a way of knowing that I have a null region. Of curse my first guess was computing the Area on it but for my polygons it is apparently impossible.
Any thoughts on why regions behave like that? and on how to know if the Intersection region is a null region?
Region
. It just turns out that the two polygons do not intersect and somehow they did not account for situations like this. You can see that there's no intersection by doing e.g.Graphics[{Red, p1, Blue, p2}]
. It really should return a null region. $\endgroup$DiscretizeRegion
seems to behave consistently on empty regions, butArea
not working here is probably a bug. WithRegionIntersection[Disk[{0, 0}, 1], Disk[{5, 5}, 1]] // Area
you get 0. $\endgroup$