Re: Moving an outsider to the closest point on the boundary
- To: mathgroup at smc.vnet.net
- Subject: [mg63666] Re: Moving an outsider to the closest point on the boundary
- From: Peter Pein <petsie at dordos.net>
- Date: Mon, 9 Jan 2006 04:49:01 -0500 (EST)
- References: <dogkjg$pui$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Borut Levart schrieb: > 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 > Hello, I'm sure you found a solution in the meantime, but here are my 2 cent: In[9]:= bringBack[{x_, y_}] := ComplexExpand[(#1[Exp[I*Arg[x + I*y]]] & ) /@ {Re, Im}] In[10]:= bringBack[p2 + dp2] d @@ % Out[10]= {0.9838699100999074, 0.17888543819998318} Out[11]= True Peter