# Put random points into a specific 2D subregion

I want to cover a particular subregion of the x-y plane with a random distribution.

As this particular region is not a circle I encounter some problems declaring the permitted zone where to put points.

The points must NOT be drawn in the blue zone. As in the graph

And I use the following code to drawing the graph:

mu = 0.000954;
h = x^2 - y^2 + 2 (1 - mu)/Norm[x + mu] + 2 mu/Norm[1 - x - mu];
S =
RegionPlot[h < 3.07, {x, -2, 2}, {y, -2, 2},
Mesh -> None, PlotPoints -> 200, Axes -> True, Frame -> False]


Where h is the function.

P.s.: the drawing process is a bit long if you use more then 200 points, so keep this not so high.

-

## 1 Answer

How about

f[x_, y_] = h - 3.07;


Then, drawing candidates

dat = {RandomVariate[UniformDistribution[{-2, 2}], np],
RandomVariate[UniformDistribution[{-2, 2}], np]} // Transpose;


and selecting

Show[Select[dat, f @@ # > 0 &] // ListPlot[#, AspectRatio -> 1] &, S]


the corresponding data can be exported as

Export["test.dat",dat]


\$cat test.dat

-
Thanks a lot !!! A very stupid question, if i want to save the coordinates of these points in a file how i can do that? THANKS ! –  Panichi Pattumeros PapaCastoro Apr 6 '14 at 14:36
in what format? –  chris Apr 6 '14 at 14:41
I solve by mayself the problem of output. Just to take the data=Select[] also out from the Show and than use Export['output.dat',data]. –  Panichi Pattumeros PapaCastoro Apr 6 '14 at 15:13
UniformDistribution can represent 2D distribution: dat = RandomVariate[UniformDistribution[{{-2, 2}, {-2, 2}}], np]. (+1 for post-Select.) –  Silvia Apr 6 '14 at 22:38
@Silvia thanks. I thought it would be called Multi UniformDistribution –  chris Apr 7 '14 at 11:26