Back to questions
How do you uniformly sample points at random from a circle with radius R?
This is the same question as problem #39 in the Statistics Chapter of Ace the Data Science Interview!
This can be proved using the inverse-transform method, whereby we sample from a uniform distribution and then simulate the points on the circle employing the inverse cumulative distribution functions (i.e., inverse CDFs).
We can define a random point within the circle using a given radius value and an angle (and obtain the corresponding x, y values from polar coordinates). To sample a random radius, consider the following.
If we sample points from a radius r, we know that there are 2πr points to consider (i.e., the circumference of the circle). Likewise, if we sample a radius 2r, there are 4πr points to consider. Therefore, we have the following probability density function given by the following:
This follows from the CDF, which is given by the ratio of the areas of the two circles:
Therefore, for the inverse sampling, we want the following:
which simplifies to the following:
Therefore, we can sample
and the corresponding radius will be the following:
For the corresponding angles, we can sample theta uniformly from the range 0 to 2π:
and then set the following: