Random Chord Length

Posted on Sat 25 March 2023 in Posts

Here is a question: pick two points on a circle of radius \(r\) independently uniformly at random.

What is the average distance between these two points?

Analysis

Let's to analyze this question using probabilistic mathematical reasoning before doing simulations.

Sampling points on a circle

To sample a point \(P=(X,Y)\) on a circle, we require

$$X^2+Y^2=r$$

Instead of dealing with two random variables, let's simplify things by using polar coordinates. We fix the radius at \(r\) and vary the angle \(\theta\) between \(0\) and \(2\pi\) uniformly:

$$\theta = U(0,\,2\pi) = \begin{cases} \frac{1}{2\pi}, &\theta\in[0, 2\pi]\\ 0,~&otherwise \end{cases}$$

For two independent points on a circle, \(P_1=(r,\,\theta_1),~P_2=(r,\,\theta_2)\), we can calculate the distance as follows

$$d(P_1,\,P_2) = \sqrt{r_1^2+r_2^2 - 2r_1r_2\cos{\left(\theta_1-\theta_2\right)}}$$

Our coordinates lie on same circle, hence \(r_1=r_2\).

$$d(P_1,\,P_2)=r\sqrt{2\left(1-\cos{\left(\theta_1-\theta_2\right)}\right)}$$

Simplifying a bit more, we get

$$d(P_1,\,P_2)=r\sqrt{2\left(2\sin^2{\left(\frac{\theta_1-\theta_2}{2}\right)}\right)}=2r\sqrt{\sin^2{\left(\frac{\theta_1-\theta_2}{2}\right)}}=2r\left\lvert\sin{\left(\frac{\theta_1-\theta_2}{2}\right)}\right\rvert$$

We seek the expected distance \(\mathbb{E}[d]\) for two independent distributions of \(\theta_1, \theta_2\). The expected value is written as

$$\mathbb{E}[d] = \int\limits_{0}^{2\pi}\int\limits_{0}^{2\pi}2r\left\lvert\sin{\left(\frac{\theta_1-\theta_2}{2}\right)}\right\rvert\frac{\mathrm{d}\theta_1}{2\pi}\frac{\mathrm{d}\theta_2}{2\pi}$$

The main point of contention here is integrating the \(\left\lvert\sin\left(\frac{\theta_1-\theta_2}{2}\right)\right\rvert\) function. The function splits in two, based on the sign of \(\theta_1-\theta_2\). Without loss of generality, we can always assume that \(\theta_1 < \theta_2\), hence we arrive at

$$\mathbb{E}[d] = \frac{2r}{4\pi^2}\int\limits_{0}^{2\pi}\mathrm{d}\theta_2\int\limits_{0}^{\theta_2}\sin{\left(\frac{\theta_2-\theta_1}{2}\right)}\mathrm{d}\theta_1$$
$$\mathbb{E}[d] = \frac{2r}{4\pi^2}\int\limits_{0}^{2\pi}\left(2\cos\left(0\right)-2\cos\left(\frac{\theta_2}{2}\right)\right)\mathrm{d}\theta_2 = \frac{r}{\pi^2} 4\pi = \frac{4r}{\pi}$$

For \(r=1\), we get

$$\mathbb{E}[d]\approx 1.2732$$

Monte-Carlo simulation code

We will define a function that computes an array of distances for random points. The size of array is given by parameter size and the radius can be specified via r.

import numpy as np

def dist(r, size=100):
    theta_1 = np.random.uniform(0,2*np.math.pi, size=size)
    theta_2 = np.random.uniform(0,2*np.math.pi, size=size)
    return 2*r*np.sin(np.abs((theta_1 - theta_2)/2))

Let us verify for r=1 and size=10000 by computing the difference between 4/pi and the call to dist:

print(abs(4/np.math.pi, dist(1, 10000).mean()))
#0.0008801268016318531

Bertrand's paradox

From colleagues at work, I discovered that this problem is closely related to a well-known paradox called Bertrand's paradox12 which I may write about in a later post.


  1. https://web.mit.edu/urban_or_book/www/book/chapter3/3.3.2.html ↩︎
  2. https://en.wikipedia.org/wiki/Bertrand_paradox_(probability) ↩︎