Extending RegionNearest to find nearest two points in two regions and their distance

DOWNLOAD-DESKTOP-NOTEBOOK.nb (44.2 KB)

4 Likes

news-congrads-kkluyshnik-02-04-19.jpg – you have earned Featured Contributor Badge 2015-11-02_10-07-11.png
Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

min[reg1_, reg2_, tolerance_] :=
Block[{
rn1 = RegionNearest[N@reg1],
rn2 = RegionNearest[N@reg2],
start, iter, pt1, pt2
},
start = RegionCentroid[reg1];
iter[pt_] := rn1[rn2[pt]];
pt1 = FixedPoint[iter, start,
SameTest → (Norm[#2 - #1] < tolerance &)];
pt2 = rn2[pt1];
{Norm[pt1 - pt2], {pt1, pt2}}
]

This version of the function does not require a point in region1. It uses RegionCentroid to generate that point.

1 Like