12
$\begingroup$

How can I obtain a precompiled RegionMemberFunction for this geometry? It contains a hole, and the hole's boundary intersects the outer boundary at one point.

region = FilledCurve[{Line[{{34.5222,-86.2377},{34.5229,-86.2345},{34.5228,-86.2332},{34.53,-86.233},{34.532,-86.2337},{34.5322,-86.2249},{34.5326,-86.2228},{34.534,-86.2209},{34.5379,-86.2186},{34.5395,-86.2165},{34.5423,-86.2108},{34.5465,-86.2056},{34.5491,-86.2016},{34.5509,-86.2003},{34.5551,-86.1993},{34.5571,-86.1975},{34.5635,-86.1896},{34.5662,-86.1842},{34.5675,-86.1806},{34.5681,-86.1753},{34.5677,-86.1733},{34.5694,-86.1725},{34.575,-86.1678},{34.5796,-86.1666},{34.581,-86.1667},{34.5823,-86.1679},{34.5863,-86.1688},{34.5935,-86.169},{34.5955,-86.1703},{34.5993,-86.1675},{34.5991,-86.1485},{34.5883,-86.1487},{34.5497,-86.1494},{34.5506,-86.1543},{34.5502,-86.1551},{34.5412,-86.1433},{34.5343,-86.1441},{34.5343,-86.1445},{34.5348,-86.1498},{34.5336,-86.1498},{34.5335,-86.1455},{34.5333,-86.1398},{34.5261,-86.1439},{34.5209,-86.1478},{34.52,-86.1456},{34.5175,-86.1479},{34.5147,-86.1522},{34.5237,-86.1622},{34.5247,-86.1638},{34.5256,-86.1677},{34.5246,-86.1709},{34.5221,-86.174},{34.5219,-86.1764},{34.509,-86.1859},{34.5106,-86.1899},{34.5128,-86.191},{34.5129,-86.1922},{34.511,-86.1938},{34.5103,-86.1956},{34.5125,-86.1953},{34.5154,-86.1975},{34.5157,-86.198},{34.5163,-86.2004},{34.5161,-86.2056},{34.5162,-86.2082},{34.5169,-86.2101},{34.5174,-86.2111},{34.519,-86.2178},{34.5199,-86.2195},{34.5199,-86.2201},{34.5127,-86.2203},{34.513,-86.2264},{34.5129,-86.2277},{34.513,-86.2379},{34.5222,-86.2377}}],Line[{{34.5336,-86.1498},{34.5336,-86.1499},{34.5338,-86.1542},{34.5301,-86.1543},{34.5302,-86.1498},{34.5333,-86.1498},{34.5336,-86.1498}}]}];
region // Graphics

enter image description here

RegionQ[region]

False

Intersection @@ Cases[region, {{__?NumberQ} ..}, Infinity];

{{34.5336, -86.1498}}

RegionMember[region]

RegionMember::regp: A correctly specified region expected at position 1...

I tried this with no luck:

diff = RegionDifference @@ First[region /. Line -> Polygon];

which gives

diff // RegionQ

True

RegionMember[diff]

RegionMember[...] (* inert *)

diff // DiscretizeRegion

DiscretizeRegion::drf: DiscretizeRegion was unable to discretize the region RegionDifference[<<2>>]

I noticed if the hole and outer boundary do not intersect, there is no problem.

l1 = Line@{{0, 0}, {0, 10}, {10, 10}, {10, 0}, {0, 0}};
l2 = l1 /. {0 -> 4, 10 -> 6};
c = FilledCurve@{l1, l2};
c // Graphics

enter image description here

RegionDifference @@ First[c /. Line -> Polygon] // RegionMember

enter image description here

Is there something better than this approach?

outer = Polygon @@ region[[1, 1]] // RegionMember
inner = Polygon @@ region[[1, 2]] // RegionMember
member[x_] := outer@x && ! inner@x;
$\endgroup$

1 Answer 1

11
$\begingroup$

Discretizing polygons first then difference facilitates. Apologies if I have misunderstood issue.

pol = Cases[region, Line[x__] :> Polygon[x], Infinity];
rm = RegionDifference @@ (DiscretizeRegion /@ pol);
rmf = RegionMember[rm]
mx = Max[pol[[1, All, #]]] & /@ {1, 2};
mn = Min[pol[[1, All, #]]] & /@ {1, 2};
Manipulate[
 Column[{Show[Graphics[Point[p]], RegionPlot[rm, PlotStyle -> c], 
    PlotRange -> Transpose[{mn, mx}], ImageSize -> 400], 
   If[rmf[p], c = Red; "True", c = Black; 
    "False"]}], {{p, {34.56, -86.2}}, Locator}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Perfect, thank you. $\endgroup$
    – mfvonh
    Jun 22, 2015 at 2:42
  • $\begingroup$ @mfvonh thank you...I made slightly more concise... $\endgroup$
    – ubpdqn
    Jun 22, 2015 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.