Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
    
Why don't you have your random number generator generate numbers that are mapped to be inside the circle as to avoid this? For example, a strategy simlar to stackoverflow.com/questions/137783/…. Also, you can look in Knuth's or in Numerical Recipes, CH 7 for such algorithms to figure out how to map them to a specified range. –  Amzoti Dec 18 '12 at 22:43
1  
@Amzoti Actually, the first recommendation in Knuth for generating random points in a circle, IIRC, is the 'generate a new one' rejection sampling approach that the OP mentions - it sounds like they're just trying to figure out how to implement it. –  Steven Stadnicki Dec 18 '12 at 22:48
    
Well then, they can find that here: stackoverflow.com/questions/5837572/… (look at the last method for quick and dirty or one of the earilier methods with the nice pictures) Regards -A –  Amzoti Dec 18 '12 at 22:54
    
Possible 2D Duplicate of: math.stackexchange.com/questions/91109/… –  FrenzY DT. Dec 19 '12 at 1:58
add comment

2 Answers

up vote 3 down vote accepted

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

share|improve this answer
    
This worked perfectly for me, thank you. –  AkBKukU Dec 19 '12 at 0:10
add comment

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.

share|improve this answer
add comment

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.