How to find the farthest distance from the point to the region?

Consider the following 2D regions:

DetectorSlice[xToDetCenter_, yToDetCenter_, dxdet_, dydet_, Rdet_,
experiment_] :=
If[experiment == "Box",
Rectangle[{xToDetCenter - dxdet/2,
yToDetCenter - dydet/2}, {xToDetCenter + dxdet/2,
yToDetCenter + dydet/2}],
If[experiment == "Cylinder",
Disk[{xToDetCenter, yToDetCenter}, Rdet], 0]];


For Box, this is a rectangle parametrized by the coordinates of its center xToDetCenter, yToDetCenter and side lengths dxdet, dydet. For Cylinder, this is a disk. Could you please tell me how to find the largest distance from the point {0,0} to the given domain?

It is trivial by hands, but how to ask Mathematica to do this automatically?

My attempt is the following. For Box, I just use MeshCordinates and choose the maximal Norm of the coordinates. For Disk, I use MeshCoordinates@DiscretizeRegion@RegionBoundary, and then do the same. The same question about possible general 2D regions.

• Not sure yet about the Rectangle geometry, but wouldn't the furthest point in the Disk geometry be the point that lies on the edge of the disk along the vector pointing from the origin to the center of the disk (but on the far side)? This distance would be calculated by Norm[{xToDetCenter, yToDetCenter}*(1 + Rdet)]
– ydd
Commented Jun 1, 2023 at 20:24
• @DavidTrimas : for these geometries, it may be simple, but how to treat possibly arbitrary regions? Commented Jun 1, 2023 at 20:27
• You could try "NMaximize". E.g. for a Disk[{1,1},1/2]: NMaximize[ If[RegionMember[Disk[{1, 1}, 1/2], {x, y}], Norm[{x, y}], 0], {x, y}, Method -> "DifferentialEvolution"] Commented Jun 1, 2023 at 20:42
• Disappointing (adapted from the docs): Subscript[\[ScriptCapitalR], 1] = ImplicitRegion[0 <= x^2 + y^2 <= \!$$\*SubsuperscriptBox[\(r$$, $$2$$, $$2$$]\), {x, y}]; Subscript[\[ScriptCapitalR], 2] = Annulus[]; RegionWithin[Subscript[\[ScriptCapitalR], 1], Subscript[\ \[ScriptCapitalR], 2]] -- should work for reasonably simple regions. :( Commented Jun 1, 2023 at 20:48
• farthestPoint[region_, point_ : {0, 0}] := ArgMax[{Norm[{x, y} - point], {x, y} \[Element] RegionBoundary[region]}, {x, y}]?
– kglr
Commented Jun 1, 2023 at 21:04

Using RegionFarthestDistance: (newly introduced with v13.3 / using the cloud account)

For a point (Red) outside a polygon:

pt=RandomReal[{-1,1},2];
poly=RandomPolygon[{"Convex",5}];
rfd=RegionFarthestDistance[poly,pt]
ptonreg=RegionIntersection[Circle[pt,rfd],poly]/.Point[{a_}]:>a


For a point (Blue) inside the polygon:

pt2=First@RandomPoint[poly,1]
rfd2=RegionFarthestDistance[poly,pt2]
ptonreg2=RegionIntersection[Circle[pt2,rfd2],poly]/.Point[{a_}]:>a


Visualization:

Graphics[{AbsolutePointSize[6],Red
,Point@pt,Darker@Green,Point@ptonreg
,Black,Dashed,Line[{pt,ptonreg}]
,{Opacity[0.2,Blue],poly}
,Dashed,Black
,Circle[pt,rfd]
,Blue,Point@pt2,Brown,Point@ptonreg2
,Dashed,Black,Circle[pt2,rfd2]
,Line[{pt2,ptonreg2}]
}
,Axes->True
]


TODO: Sometimes, the RegionIntersection fails to find the single point of intersection (reason unknown). At times, it results in a degenerate circle with a infinitesimal arc.

The circles are centered at blue and red points.

So far, I haven't been able to extract the farthest point from the RegionFarthestDistance itself. The name implies that this function is not responsible for providing it (and perhaps there exists another mechanism to get that information). If the farthest distance is available, a reasonable assumption is that there was a point that was used in such a calculation.