Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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