Calculating Expected Distance to Center on a Disc

On a unit disc, what is the expected distance from a uniformly random point to its center?

At a glance and letting intuition take over, it might seem that the answer is 0.5, given that the distance is between 0 and 1 and the point is uniformly distributed. If that were the case, your intuition is wrong. To prove why I propose two solutions: one using trustworthy integrals and the second one that employs a geometrical transformation.

Solution 1

Start with a sketch of the disc D, observing that the density of the point over it is the identity function, hence 1 divided by pi over the entire area. Using the most elementary definition of the expectation:

E=Dd(O,X)dD dA=1πDd(O,X) dA\mathbb{E}=\displaystyle\iint\limits_{\text{D}} d(O, X) \cdot {\text{dD}}\ \text{dA} = \dfrac{1}{\pi} \displaystyle\iint\limits{\text{D}} d(O, X) \ \text{dA}

In this formula, dA\text{dA} represents the differential, showing us which value is infinitesimally changed when integrating. This is obviously a very general formula, that has to be adapted to our momentary needs. At a minimum, we have to be able to describe space D: Cartesian Coordinates: D={(x,y)  x,y[1,1], x2+y21}D = \lbrace (x,y)\ |\ x,y \in [-1,1],\ x^2 + y^2 \leq 1 \rbrace

Plug this into the basic formula, and we see that we have a less-than-pretty integral: E=1π111x21x2d(O,X) dydx=1π111x21x2x2+y2 dydx\mathbb{E} = \dfrac{1}{\pi} \displaystyle\int_{-1}^1 \displaystyle\int_{-\sqrt{1-x^2}}^{\sqrt{1-x^2}} d(O, X) \ \text{dy}\text{dx} = \dfrac{1}{\pi} \displaystyle\int_{-1}^1 \displaystyle\int_{-\sqrt{1-x^2}}^{\sqrt{1-x^2}} \sqrt{x^2+y^2} \ \text{dy}\text{dx}

This is solvable, but it requires integrating by parts, remembering how to integrate 1(x2+C)\frac{1}{\sqrt(x^2 + C)}, and doing so correctly under pressure. It might be a tall order.

Is there another way to describe D? Can polar coordinates be our saviors in this case? Even though we speak of the same space -D-, we denote it by “D*”, since now it is parameterized with polar coordinates. Polar Coords: D={(rcosθ,rsinθ)r[0,1],θ[0,2π)}\text{D}^* = \lbrace (r\cos \theta,r\sin \theta) \mid r \in [0,1], \theta \in [0, 2\pi) \rbrace

To do this we need a change of variable, which introduces the determinant of the Jacobian in the formula, besides the change of integral limits. E=1πDrJ(r,θ) dr dθ\mathbb{E} = \dfrac{1}{\pi}\displaystyle\iint\limits_{\text{D}^*}r \cdot |J(r,\theta)| \ \text{dr} \ \text{d}\theta E=1π02π01rJ(r,θ) dr dθ\mathbb{E} = \dfrac{1}{\pi} \displaystyle\int_0^{2\pi} \displaystyle\int_0^1 r \cdot |J(r,\theta)| \ \text{dr} \ \text{d}\theta E=1π02π01rJ(r,θ) dr dθ\mathbb{E} = \dfrac{1}{\pi} \displaystyle\int_0^{2\pi} \displaystyle\int_0^1 r \cdot |J(r,\theta)| \ \text{dr} \ \text{d}\theta

Let’s write down the Jacobian matrix and compute its determinant. J(r,θ)=dxdrdxdθdydrdydθ=cos(θ)rsin(θ)sin(θ)rcos(θ)=rcos2(θ)+rsin2(θ)=r|J(r,\theta)| = \begin{vmatrix} \frac{dx}{dr} & \frac{dx}{d\theta} \\ \frac{dy}{dr} & \frac{dy}{d\theta} \end{vmatrix} = \begin{vmatrix} \cos(\theta) & -r\sin(\theta) \\ \sin(\theta) & r\cos(\theta) \end{vmatrix}=r\cdot \cos^2(\theta) + r \cdot \sin^2(\theta)=r

We put this final piece of the puzzle in place and compute the now much easier integral. E=1π02π01r2 dr dθ\mathbb{E}=\dfrac{1}{\pi} \displaystyle\int_0^{2\pi} \displaystyle\int_0^1 r^2 \ \text{dr} \ \text{d}\theta =1π02πr3301 dθ=1π02π13 dθ=\dfrac{1}{\pi} \displaystyle\int_0^{2\pi} \left.\dfrac{r^3}{3}\right|_{0}^1 \ \text{d}\theta = \dfrac{1}{\pi} \displaystyle\int_0^{2\pi} \dfrac{1}{3}\ \text{d}\theta =1πθ302π=1π2π3=23=\dfrac{1}{\pi}\cdot \left.\dfrac{\theta}{3}\right|_0^{2\pi} = \dfrac{1}{\pi} \cdot \dfrac{2\pi}{3} = \dfrac{2}{3}

The final result is 2/3, just as I warned, not equal to a half.

Solution 2

As promised, the above solution is not the only way to solve this problem. Another one employs a one-to-one transformation of the area of the disc in the area of a triangle as such:

  • peel the circle into thin circles and lay them out flat, parallel one to another.

The side of the triangle opposite the center measures the length of the circle, 2π2\pi, and is situated at distance 1, the radius of the disc, from the center. All the points on one given circle have the same x coordinate in the newly formed triangle. The construction above gives us the freedom to make the triangle isosceles symmetrical to the x-axis. We now have an equivalent problem: For a uniformly random point inside the triangle AOB, what is the expected value of its x coordinate? We find the coordinates of the center of mass to be 2/3 and 0. So this means that the expected x coordinate is 2/3, which further solidifies the previous result.

Coding Check

And the last method to find the expected distance is to simulate points on the disc using the given expectation. The code proposed uses a more particular approach, simulating uniformly random points inside a square, and then cutting them to the inside of the disc. As an exercise, you can attempt to prove that this approach yields uniformly random points inside the disc. An alternative way to do this is to use polar coordinates, but be careful when choosing the distribution of the radius. It might not be what you expect it to be.

import random def getPointInSquare(): x = random.uniform(-1, 1) y = random.uniform(-1, 1) return (x,y) def getPointInDisc(): is_on_disc = False while not is_on_disc: x,y = getPointInSquare() if x**2+y**2<=1: is_on_disc = True return (x,y) points = distances = print(f"Avg dist: {np.mean(distances)}")