I need to generate a uniformly random point within a circle of radius R.
I realize that by just picking a uniformly random angle in the interval [0 ... 2π),
You can also use your intuition.
The area of a circle is pi*r^2
For r=1
This give us an area of pi
. Let us assume that we have some kind of function f
that would uniformly distrubute N=10
points inside a circle. The ratio here is 10 / pi
Now we double the area and the number of points
For r=2
and N=20
This gives an area of 4pi
and the ratio is now 20/4pi
or 10/2pi
. The ratio will get smaller and smaller the bigger the radius is, because its growth is quadratic and the N
scales linearly.
To fix this we can just say
x = r^2
sqrt(x) = r
If you would generate a vector in polar coordinates like this
length = random_0_1();
angle = random_0_2pi();
More points would land around the center.
length = sqrt(random_0_1());
angle = random_0_2pi();
length
is not uniformly distributed anymore, but the vector will now be uniformly distributed.