2
$\begingroup$

I know that by just using a random angle and a random radius within the bounds of your circle, you will end up with points near the center of a circle. Whereas if you do $\sqrt{Random(0,1)}*MaxRadius$ for your radius, you will end up with what appears to be a uniformly random point. I am happy this works but I would like to understand where the square root comes from. The Square Root function in this calculation seems magical to me and I would like to know what it means in this context.

$\endgroup$
3
$\begingroup$

You wish to uniformly distribute points around a disc of radius $R_{\max}$ and centre $\langle 0, 0\rangle$.

As noted, naïvely choosing $\Theta\sim\mathcal U(-\pi;\pi]$ and $R\sim\mathcal U[0;R_{\max}]$ as the distribution of polar coordinates will result in a Cartesian point distribution that is too dense near the centre and too disperse near the rim.   In fact a Cartesian point's probability density will be inversely proportional to its radial distance.   So we must compensate for this.

We can do this by choosing $R$ using triangular distribution: $R\sim\mathcal T(0,R_{\max},R_{\max})$, which had density $f_R(r) = 2r/R^2_{\max}$ for $r\in[0;R_{\max}]$.   Thereby compensating.

A way to generate random numbers for this distribution is to choose a uniformly distributed variable and take the square root of the results.   That is: Let $S\sim\mathcal U[0;R_\max^2]$ and set $R=\sqrt{S\,}$.

By a change of variables (chain rule) we can show that gives $R$ the required distribution. $$\begin{align}f_S(s) & = 1/R^2_\max\\ f_R(r) & = f_S(r^2)\left\lvert\dfrac{\mathrm d r^2}{\mathrm d r}\right\rvert \\ & = 2 r/R^2_\max \end{align}$$

Thus a uniform distribution of points in a disc has polar coordinates distributed as $\Theta\sim\mathcal U(-\pi;\pi], \underbrace{R^2}_{S}\sim\mathcal U(0;R_\max^2)$

Which is generated by your code $\rm Let\; Angle = (Random(0,1)*2-1)*Pi\\Let\; Radius = Sqrt(Random(0,1)) * MaxRadius\\ Let\; XOrdinate = Radius*\cos(Angle)\\Let\; YOrdinate=Radius*\sin(Angle)$

$\endgroup$
2
$\begingroup$

The point is that the area of the circle of radius $r$ is $\pi r^2$, and you want the probability of distance $\le r$ from the centre to be proportional to that area.

$\endgroup$
5
  • $\begingroup$ So you are saying that we want to make sure that the probability of our random radius can cover the area of our circle. That makes sense but I don't see the connection with the formula I posted. A random number between 0 and 1 can be multiplied by our circle's radius to put our random radius in the same space as our circle's radius. I understand that part. I also see that in the circle's area formula, we square the radius. So we are doing the reverse by taking the square root of our random radius. But I don't know why we would have ever thought to do that. $\endgroup$
    – akaitora
    Jun 1 '15 at 2:19
  • $\begingroup$ I might be a bit closer to understanding. I see that the following is true. $r = \sqrt{\frac{Area}{\pi}}$ but I don't know how the random 0 to 1 based radius correlates to $\frac{Area}{\pi}$ on a circle whose radius is 1. $\endgroup$
    – akaitora
    Jun 1 '15 at 2:46
  • $\begingroup$ Is it because $A = \pi*1^2 = \pi$ therefore $\frac{A}{\pi} = 1$ where 0 to 1 is the domain of the random function? $\endgroup$
    – akaitora
    Jun 1 '15 at 2:52
  • $\begingroup$ Suppose $X$ is uniformly distributed on $[0,1]$ and you take $R = \sqrt{X}$. Then for any $r \in [0,1]$, $\text{Prob}(R < r) = \text{Prob}(X < r^2) = r^2$, which is what you want. $\endgroup$ Jun 1 '15 at 2:55
  • $\begingroup$ I believe your earlier answer is closer to what I was looking for. You said that the area of a circle is $A = \pi*r^2$. As you said, I need to make sure the probability of the radius distance is proportional to the area of the circle. So really, I need a function that can accurately compute the radius of a circle which would be $R = \sqrt{\frac{A}{\pi}}$. The Area of a circle whose radius is 1, is 1. So I can substitute $\frac{A}{\pi}$ for $r \in [0,1]$ thus $\sqrt{r \in [0,1]}*Radius = Random Radius$. Am I wrong? $\endgroup$
    – akaitora
    Jun 2 '15 at 1:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.