Moving an outsider to the closest point on the boundary

*To*: mathgroup at smc.vnet.net*Subject*: [mg63322] Moving an outsider to the closest point on the boundary*From*: "Borut Levart" <BoLe79 at gmail.com>*Date*: Fri, 23 Dec 2005 05:08:43 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

Respected subscribers of comp.soft-sys.math.mathematica, I have bumped into a problem which I cannot solve. I have defined a distance function d(x,y) that says True in the inside of the closed geometry of interest and False outside. Initially there are some points inside the geometry. My iterating algorithm moves those points. Some stay inside while others may drift away over the boundary to the outside. I would like to select those outsiders and move them back in, however, not in any way: I want to move them back to the closest point on the boundary. (This corresponds to the physical analogy of my work.) Here is an example of a unit circle as defined geometry and two points: In[1]:= d[x_, y_] := x^2 + y^2 = 1 p1 = {0, 0}; p2 = {.8, .5}; dp1 = {-.1, -.1}; dp2 = {.3, -.3}; In[2]:= DensityPlot[ If[d[x, y], 1, -1], {x, -2, 2}, {y, -2, 2}, PlotPoints -> 100, Mesh -> False, Epilog -> { Hue[0], PointSize[.02], Point /@ {p1, p2}, Hue[.6], Point /@ {p1 + dp1, p2 + dp2} } ] After each iteration I would like to correct the set of points by doing something like this: In[3]:= If[! d @@ #, bringBack[#, d2 @@ #], #] & /@ {p1 + dp1, p2 + dp2} Out[3]:= {{-0.1, -0.1}, bringBack[{1.1, 0.2}, d2[1.1, 0.2]]} But, bringBack? Thank you for your time and suggestions, Borut Levart