Message Boards Message Boards

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

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

Attachments:
POSTED BY: Frank Kampas
2 Replies

enter image description here -- you have earned Featured Contributor Badge enter image description here 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!

POSTED BY: EDITORIAL BOARD
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.

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract