Mathematica Asked by SneezeFor16Min on June 27, 2021
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.
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}}
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}}
Answered by cvgmt on June 27, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP