3
$\begingroup$

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 graphenter image description here

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.

$\endgroup$

2 Answers 2

6
$\begingroup$

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]

dots

the corresponding data can be exported as

Export["test.dat",dat]

$cat test.dat

$\endgroup$
5
  • $\begingroup$ 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 ! $\endgroup$ Apr 6, 2014 at 14:36
  • $\begingroup$ in what format? $\endgroup$
    – chris
    Apr 6, 2014 at 14:41
  • $\begingroup$ 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]. $\endgroup$ Apr 6, 2014 at 15:13
  • 2
    $\begingroup$ UniformDistribution can represent 2D distribution: dat = RandomVariate[UniformDistribution[{{-2, 2}, {-2, 2}}], np]. (+1 for post-Select.) $\endgroup$
    – Silvia
    Apr 6, 2014 at 22:38
  • $\begingroup$ @Silvia thanks. I thought it would be called Multi UniformDistribution $\endgroup$
    – chris
    Apr 7, 2014 at 11:26
4
$\begingroup$

This is now easily done with the current region functionality:

With[{mu = 0.000954, val = 3.07},
     reg = ImplicitRegion[x^2 - y^2 + 2 (1 - mu)/Norm[x + mu] + 2 mu/Norm[1 - x - mu] <
                          val, {{x, -2, 2}, {y, -2, 2}}]];

(* discretize complement *)
cr = BoundaryDiscretizeRegion[RegionDifference[Rectangle[{-2, -2}, {2, 2}], reg]];

RegionPlot[reg, Epilog -> {AbsolutePointSize[1], Point[RandomPoint[cr, 5000]]}]

random points outside a region

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.