2
$\begingroup$

I am generating two random numbers to choose a point in a circle randomly. The circles radius is 3000 with origin at the center. I'm using -3000 to 3000 as my bounds for the random numbers. I'm trying to get the coordinates to fall inside the circle (ie 3000, 3000 is not in the circle). What equation could I use to test the limits of the two numbers because I can generate a new one if it falls out of bounds.

  • 0
    Possible 2D Duplicate of: http://math.stackexchange.com/questions/91109/get-random-x-y-z-point-inside-a-sphere2012-12-19

2 Answers 2

3

Compare $x^2+y^2$ with $r^2$ and reject / retry if $x^2+y^2\ge r^2$.

  • 0
    This worked perfectl$y$ for me, thank $y$ou.2012-12-19
0

Another way. Choose a random angle between 0 and 2PI. Then choose a random number between 0 and r. pt(x,y) =

Note that it isn't uniform.