1
$\begingroup$

Code as simple as it is:

targetRegion = RegionUnion[Disk[{0, 0}], Disk[{1.8, 0}]];
edgeDistFn = RegionDistance[RegionBoundary@targetRegion]
pts = RandomPoint[targetRegion, {2, 2}];
pts // edgeDistFn

This should give distances of all points to the boundary, but works on neither 12.1.1 nor 12.2, with output like:

{{RegionDistance[
   RegionBoundary[
    BooleanRegion[#1 || #2 &, {Disk[{0, 0}], 
      Disk[{1.8, 0}]}]], {-0.4243129646, 0.5777295089}], 
  RegionDistance[
   RegionBoundary[
    BooleanRegion[#1 || #2 &, {Disk[{0, 0}], 
      Disk[{1.8, 
        0}]}]], {1.227762454, -0.3983038364}]}, {RegionDistance[
   RegionBoundary[
    BooleanRegion[#1 || #2 &, {Disk[{0, 0}], 
      Disk[{1.8, 0}]}]], {2.160377018, 0.6768344764}], 
  RegionDistance[
   RegionBoundary[
    BooleanRegion[#1 || #2 &, {Disk[{0, 0}], 
      Disk[{1.8, 0}]}]], {1.547838415, -0.00215747549}]}}

Is this a bug or an individual issue?


Despite @cvgmt's answer (a makeshift, inaccurate, and numerical solution), the reason why we need to discretize the region (in many cases, especially those where $\mathtt{Disk}$s, $\mathtt{Cone}$s, etc., are involved in $\mathtt{RegionUnion}$, $\mathtt{RegionIntersection}$, etc.) or most of the functions for region measurement will fail to work is still unclear.

$\endgroup$
2
  • $\begingroup$ Don't use the bugs tag until other people have already confirmed that what you have is a bug. $\endgroup$ Commented Jan 22, 2021 at 3:21
  • $\begingroup$ @J.M. Get it. Thanks! :) $\endgroup$ Commented Jan 22, 2021 at 3:29

1 Answer 1

4
$\begingroup$

Updated

We also need DiscretizeRegion

SeedRandom[1];
targetRegion = 
  RegionUnion[Disk[{0, 0}], Disk[{1.8, 0}]] // DiscretizeRegion;
pts = RandomPoint[targetRegion, {2, 2}];
values = SignedRegionDistance[targetRegion][pts]
Show[targetRegion // Region, 
 Graphics[{PointSize[Large], Red, Point /@ pts, 
   MapThread[Circle, {pts, Abs@values}, 2]}]]

{{-0.599128, -0.208482}, {-0.425123, -0.179378}}

enter image description here

Original

It is recommended to use SignedRegionDistance.

SeedRandom[1];
targetRegion = RegionUnion[Disk[{0, 0}], Disk[{1.8, 0}]];
pts = RandomPoint[targetRegion, {2, 2}];
values = SignedRegionDistance[targetRegion][pts]
Show[targetRegion // Region, 
 Graphics[{PointSize[Large], Red, Point /@ pts, 
   MapThread[Circle, {pts, Abs@values}, 2]}]]

{{-0.238752, -1.27}, {-0.471944, -0.548317}}

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ Thanks! This is accurate compared to RegionDistance[targetRegion // RegionBoundary // DiscretizeRegion][pts] — though I still wonder why RegionDistance hasn't done its job well. $\endgroup$ Commented Jan 22, 2021 at 3:33
  • $\begingroup$ @SneezeFor16Min It seems that there are something problem on my code , see the graphis. I think the problem come from the RegionUnion $\endgroup$
    – cvgmt
    Commented Jan 22, 2021 at 4:16
  • $\begingroup$ I see. Strange. Discretizing the boundary as I mentioned above, however, does give correct radii (albeit inaccurate): {{0.2361000112, 0.4516728083}, {0.4690868471, 0.5453502001}} $\endgroup$ Commented Jan 22, 2021 at 4:28

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.