4

Assume there is a unit disk with radius = 1 and centered at $C$. Randomly and uniformly pick a point $P$ in the disk. What is the expected distance between $C$ and $P$?

Solution:

Since $P$ is $\bf{Uniformly Distributed}$, we know the probability is $\frac{1}{\pi}$, use polar coordinates substitution $x = r\cos{\theta}$ and $y = r\sin{\theta}$, we know

$E[\sqrt{x^2+y^2}] = \frac{1}{\pi}\int_{0}^{2\pi}\int_0^1r*rdrd\theta = \frac{2}{3} $

Here is the problem. How do we generate a uniformly randomly distributed $P$ in real life?

At my original thinking, there are two independent variables, $\theta$ and $r$, every point in the disk can be represented by these two variables. Thus, we uniformly pick an angle from $[0, 2\pi)$ and distance from $[0, 1)$. But in this way, the probability of choosing a point becomes $\frac{1}{2\pi}*1=\frac{1}{2\pi}$ , which is different from $\frac{1}{\pi}$ that I claimed before. Also, in this setup, the expected distance from any point to the center becomes $\frac{1}{2}$, since it is $[0, 1)$ uniform distribution.

This contradiction gives me trouble and I can only conclude that the distance probability isn't uniform $[0, 1)$ distributed. Actually, from this link http://mathworld.wolfram.com/DiskPointPicking.html

it actually says that "The probability function for distance d from the center of a point picked at random in a unit disk is $P(d) = 2d$.

Indeed, if this is the probability function for distance, the expectation is easy to calculate, $\int_0^1 2rdr=\frac{2}{3}$, which is the same as before. Also, the total probability becomes $\int_0^{2\pi} \int_0^1 2r(\frac{1}{2\pi})rdrd\theta = 1$.

I know why $dxdy = rdrd\theta$ when transforming $x,y$ to $r, \theta$, but it is not that easy to imagine the distance is not uniformly distributed. Can someone give an easy to understand explanation?

Follow-up question, what if the shape of object is more complicated? As an example, if on x-y plane, I draw a equilateral triangle and be asked to uniformly pick a point inside the triangle, how to do it? Previously, I was thinking use rotation matrix. Give the vector representation of two sides, each decides an angle (uniformly between $[0,\frac{\pi}{3}]]$ to rotate. But now I'm very worried that this way, it cannot generate really uniformed distributed points. What if the triangle is not symmetric?

BruceET
  • 52,418
  • 2
    Good point, the product distribution is not uniform. To see that intuitively, note that the small "square" $[r,r+dr]\times [\theta,\theta+d\theta]$ has a lot more area when $r$ is big then when $r$ is small. – lulu Sep 10 '17 at 03:26
  • this question gives some good code relevant to your question. – lulu Sep 10 '17 at 03:30
  • The R code is interesting.

    Follow-up question, if this uniform angle and distance cannot generate the desired uniform distributed points in the circle, what if the shape of object is more complicated?

    As an example, if on x-y plane, I draw a equilateral triangle and ask to uniformly pick a point inside the triangle, how to do it? Previously, I was thinking use rotation matrix. Give the vector representation of two sides, each decides an angle (uniformly between $[0, \frac{pi}{3}]$ to rotate. Does this still generate uniform distributed points?

    – nickdon2006 Sep 10 '17 at 03:37
  • 2
    If your point is only simulation of a uniform distribution in a disk, you surely know that the classical (and efficient!) method is by generating a uniform distribution in a circumscribed square and only keep the points that fall inside the disk. – Jean Marie Sep 10 '17 at 04:14
  • To the triangle variant, here is a relevant question. – lulu Sep 10 '17 at 11:45
  • @lulu, that's lovely! I wonder if it's somehow equivalent to my suggestion below? – G Tony Jacobs Sep 10 '17 at 14:46
  • @GTonyJacobs Certainly looks related, at least. And I concur with those who have said that in practice it is often much easier to put your desired region in a rectangle, choose uniformly in the rectangle, and reject the exterior. – lulu Sep 10 '17 at 14:49

3 Answers3

2

Consider two bands of points: those whose distances from the center are on the interval $[0.1,0.2]$, and those whose distances are on the interval $[0.8,0.9]$. Note that the second band has greater area than the first band, and it is thus more likely to pick a point in the second band, if the distribution is uniform.

Does that help?

G Tony Jacobs
  • 32,044
  • Yes, this helps. Now I come up with another question, what if I have a triangle that is not symmetric? How do I randomly pick a point in it? – nickdon2006 Sep 10 '17 at 03:48
  • Do you want the distribution to be uniform? – G Tony Jacobs Sep 10 '17 at 03:49
  • Yes, I want to point in the triangle is uniform. For example, I have a triangle with 45 degrees, 30 degrees and 105 degrees. How to uniformly pick a point inside it? – nickdon2006 Sep 10 '17 at 03:55
  • First, pick a side, and call it the "base". Let the height from that base equal $H$. Now, choose a distance $d$ from the base by choosing a random number $x$ uniformly distributed on $[0,1]$, and setting $d=H(1-\sqrt{1-x})$. This works, because any $x$ between $0$ and $\frac34$ will end up below $\frac12 H$, any $x$ between $0$ and $\frac89$ will end up below $\frac23 H$, etc., which is consistent with areas. After choosing a height, you can choose the left-right location along that height line uniformly. I think this works. – G Tony Jacobs Sep 10 '17 at 04:19
  • 1
    The circumscribed square method suggested in a comment above seems easier! – G Tony Jacobs Sep 10 '17 at 04:20
  • Nice intuitive explanation why polar method doesn't give a uniform distribution on the circle (+1) Also see @lulu's explanation in first Comment. – BruceET Sep 11 '17 at 01:43
1

The distance distribution has this form: $$p(r)=\frac{2 \pi r}{\pi R^{2}} = \frac{2 r}{R^{2}}$$ so linear, rather than uniform, really.

0

This answer is centered on the question about generating points at random in the unit disk. A simple method has two steps, as Commented by @JeanMarie:

(a) Generate candidate points at random in the square with vertices at $(-1,-1)$ and $(1,1).$ This can be done by generating $x$-coordinates from $\mathsf{Unif}(-1,1)$ and independently generating $y$-coordinates according to the same uniform distribution.

(b) Then retain only points falling inside the disk.

This is implemented in R statistical software as below. The final statements explore the $\mathsf{Beta}(2,1)$ distribution of distances $D$ from the accepted points to the center.

set.seed(1234);  m = 10^6
x.cand = runif(m, -1, 1);  y.cand = runif(m, -1, 1)
d.cand = sqrt(x.cand^2 + y.cand^2);  inside = (d.cand < 1)
x = x[inside];  y = y[inside];  d = d.cand[inside]
mean(d);  sd(d)
## 0.6666624    # aprx E(D) = 2/3
## 0.2356152    # aprx SD(D) = sqrt(1/18)
mean(inside)
## 0.784404     # fraction of accepted points, aprx pi/4

hist(d, prob=T, col="skyblue2")
curve(dbeta(x, 2, 1), lwd=2, col="red", add=T)

enter image description here

A million candidates were generated and $784\,404$ of them were accepted. The illustration below shows only $50\,000$ points (for clarity), corresponding accepted ones in red.

enter image description here

BruceET
  • 52,418