Group Abstract Group Abstract

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
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
POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard