Friday, 9 November 2012

Uniformly Distributed Random Points Inside a Circular Ring

I will continue my series of posts on generating uniformly distributed points within different shapes by considering a circular ring (a.k.a. annulus or doughnut). Just like my previous post we have the joint probability density function (PDF) of the \(x\) and \(y\) coordinate of the random points as:

$$ f_{X,Y}(x,y)=
\begin{cases}
\frac{1}{A}=\frac{1}{\pi (R_{c_2}^2-R_{c_1}^2)} & R_{c_1}^2 \leq x^2+y^2 \leq R_{c_2}^2 \\
0 & \text{otherwise}
\end{cases},$$
where \(R_{c_2}\) is the radius of the outer circle and \(R_{c_1}\) is the radius of the inner circle, and \(R_{c_1}<R_{c_2}\)

Using a similar technique as in the previous post we have:
$$ f_{R,\Theta}(r,\theta) = \frac{1}{2\pi} \times \frac{2r}{R_{c_2}^2-R_{c_1}^2} = f_\Theta(\theta)f_R(r) $$
where
$$f_\Theta(\theta) = \frac{1}{2\pi} \text{ for } 0 \leq \theta \leq 2\pi$$
and
$$f_R(r)=\frac{2r}{R_{c_2}^2-R_{c_1}^2} \text{ for } R_{c_1} \leq r \leq R_{c_2}.$$
  
Therefore, \(\Theta\) is uniformly distributed between \(0\) and \(2\pi\). The random variable \(R\) can be generated by first calculating its cumulative distribution function as
$$ F_R(r) = \int_{R_{c_1}}^r \frac{2\alpha}{R_{c_2}^2-R_{c_1}^2}d\alpha = \frac{r^2-R_{c_1}^2}{R_{c_2}^2-R_{c_1}^2}, $$
and then using a uniformly distributed random variable \(U\) over the interval \([0,1]\) to get
$$ U = \frac{R^2-R_{c_1}^2}{R_{c_2}^2-R_{c_1}^2} \implies R = \sqrt{(R_{c_2}^2-R_{c_1}^2)U + R_{c_1}^2}. $$

The following MATLAB code generates 1000 random numbers inside a circular ring with outer radius \(20\), and inner radius \(10\) centered at \(-30\), \(-40\).
 
%********************************************** 
n = 10000;
Rc2 = 20;
Rc1 = 10;
Xc = -30;
Yc = -40;

theta = rand(1,n)*(2*pi);

r = sqrt((Rc2^2-Rc1^2)*rand(1,n)+Rc1^2);
x = Xc + r.*cos(theta);
y = Yc + r.*sin(theta);

plot(x,y,'.'); axis square

%********************************************** 


5 comments:

  1. Hi there,

    Your post really helps me. Did you publish this somewhere ? I am trying to use this in my paper and try to find one of your paper as a citation.

    ReplyDelete
  2. Thanks a lot.

    ReplyDelete
  3. Hello Nariman,
    I'm trying to use this information in my thesis. I'm wondering about how to cite this in my thesis?
    Thanks,

    ReplyDelete