xikka

A collection of things I have made and things I find interesting.


Follow your dart

Thursday, 1st November 2018 ◆ A bard trod clumsily on cork circle (9)

Imagine throwing a dart at a dartboard such that it will hit any point on the dartboard uniformly randomly. What is the expected distance between the dart and the centre of the dartboard?

Firstly, a clarification. When I say "uniformly randomly", I mean the probability of a dart landing in any particular location is the same as any other location.

You may like to try and work out the answer before I delve in. What seems about right to you?

I'm going to solve this in two ways. Firstly, a mathsy way which requires a little bit of probability knowledge. Then, I'll try an intuitive method which is less rigorous, but which might be more satisfactory.

Mathsy method

First, let's consider an inner circle on the dartboard with radius \( d \), I'll call this section \( I_d \). Note that this is only valid where \( 0 \le d \le r \).

Inner section Inner section

The probability of landing in this inner section is simply what percentage of the entire dartboard it takes up. For example, if \( d = r/2 \), the inner circle occupies \( 1/4 \) of the dartboard, and so the chance of landing inside it is \( 1/4 \).

$$ \mathbb{P}(\text{dart lands in}\ I_d) = \frac{\pi d^2}{\pi r^2} = \frac{d^2}{r^2} $$

Let \( D \) be the random variable which represents the distance between the dart and the centre. For example, if you throw a dart and hit the dead centre, \( D \) would take the value \( 0 \). If you hit somewhere on the edge, \( D \) would take the value \( r \).

Doing this, we can represent the probability above in terms of \( D \):

$$ \mathbb{P}(D \le d) = \mathbb{P}(\text{dart lands in}\ I_d) = \frac{d^2}{r^2} $$

This is called the cumulative distribution function, or cdf. We are going to use a theorem which lets us derive the expected value from the cdf. It's explained here if you are interested. This gives us the following integral:

$$ \mathbb{E}(D) = \int_0^r 1 - \frac{x^2}{r^2} \text{d}x = \frac{2r}{3} $$

And that is our answer: \(2r/3\).

Intuitive method

To find the expected value we sum all the values we can get and divide by the number of values. For example, if we had a die with faces \((1,2,3,6,6,6)\) our expected value would be \(\frac{1+2+3+6+6+6}{6}\).

In our case, the value of an outcome is the distance from the dartboard. The number of values is how many places the dart can land.

$$ \mathbb{E}(D) = \frac{\text{sum of all possible distances}}{\text{number of places dart can land}} $$

To find the "sum of all possible distances", imagine the dartboard lies flat. For each point on the dartboard, I will extrude upwards to the height of the distance from the centre of the dartboard. For example, at a distance of \(r\), the radius of the dartboard, I will extrude a hollow cylinder of height \(r\). Now do this for every possible distance from the centre:

Inverted cone Inverted cone

Hopefully you can see that we've created an inverted cone. The volume of this shape represents the sum of all the possible distances the dart can land at – for every point we are adding its respective distance from the centre. I'm using the word "sum" loosely here, but I hope you can see general principle.

To find the volume of the inverted cone, we subtract the volume of the cone from that of the cylinder:

$$ \begin{aligned} V_{\text{inverted cone}} &= V_{\text{cylinder}} - V_{\text{cone}} \\ &= \pi r^2 h - \frac{\pi r^2 h}{3} \\ &= \frac{2 \pi r^3}{3} \end{aligned} $$

The "number of places" the dart can land is simply the area of the dartboard. Finding that is easy, it's \(A = \pi r^2\).

Combining this together gives us:

$$ \mathbb{E}(D) = \frac{V_{\text{inverted cone}}}{A} = \frac{2 \pi r^3 / 3}{\pi r^2} = \frac{2r}{3} $$

We get the same answer: \(2r/3\). I hope that gives some credence to the mathsy answer!

What next

The reason I started thinking about this is for a simple problem I've had in game-making. I discuss that in another blog post: round in circles.

That aside, there are so many interesting things to experiment with. What happens if the dartboard is square? If we throw two darts, what's the expected distance between them? If we throw three, what's the expected area of the triangle they define? Have a play, at let me know if you come up with anything cool!

Comments

Neb ◆ Monday, 9th March 2020 at 23:12

Another solution that doesn't require using the cdf:

Consider a small area \(dA = dx.dy\) at position \((x, y)\) in the circle. Because the position is uniformly distributed, the probability that the area \(dA\) is chosen is $$ \frac{dA}{area\ of\ circle} = \frac{dA}{\pi r^2} $$

The expected value, \(E\), of a random variable, \(X\), is $$ E(X) = \sum_{x}{x P(X = x)} $$

For example in the die with faces \(1, 2, 3, 6, 6, 6\) we have $$ E(X) = 1*\frac{1}{6} + 2*\frac{1}{6} + 3*\frac{1}{6} + 6*\frac{1}{2} = 4 $$, the same value as above. The expected value of the distance, \(D\), is therefore $$ E(D) = \sum_{x,y}{\left( \sqrt{x^2 + y^2} * \frac{dA}{\pi r^2} \right ) } = \frac{1}{\pi r^2}\sum_{x,y}{\sqrt{x^2 + y^2} dx dy} $$

where \(\sqrt{x^2 + y^2}\) is the distance from the origin to \(dA\) and \(\pi r^2\) can be factored out because it's constant. In the limit as \(dA\), and hence \(dx\) and \(dy\), go to 0 this becomes an integral, $$ E(D) = \frac{1}{\pi r^2} \iint{\sqrt{x^2 + y^2} dxdy} $$

With a change of basis, \(x = r \cos(\theta), y = r \sin(\theta)\), we have that \(dx dy = r dr d\theta\) and the integral becomes $$ E(D) = \frac{1}{\pi r^2} \iint{(r) * (r dr d\theta)} = \frac{1}{\pi r^2} \iint{r^2 dr d\theta} $$

The domain of this integral is over the entire circle, so \(r=[0,r], \theta=[0,2\pi]\), and so $$ E(D) = \frac{1}{\pi r^2} \int_{0}^{2\pi}\int_{0}^{r}{r^2 dr d\theta} = \left( \frac{1}{\pi r^2}\right ) \left (\int_{0}^{r}{r^2}dr \right ) \left( \int_{0}^{2\pi} d\theta \right ) = \left(\frac{1}{\pi r^2} \right ) \left(\frac{r^3}{3}\right) \left(2 \pi\right) = \frac{2r}{3} $$

Neb ◆ Tuesday, 10th March 2020 at 00:11

The area-based solution can also be extended to provide an answer for the square and 2 darts problems:

For the problem of finding the expected distance for a square, simply changing the bounds of the integral from a circle to a square of side \(2 r\), and noting that the area is now \(4 r^2\) instead of \(\pi r^2\), gives us:

$$ E(D) = \frac{1}{4 r^2} \int_{-r}^{r}\int_{-r}^{r}{\sqrt{x^2 + y^2} dxdy} $$

According to Wolfram Alpha this evaluates to $$ E(D) = \frac{r}{3}\left(\sqrt{2} + \sinh^{-1}\left(1 \right ) \right ) \approx 0.765r $$

which isn't that much more than the \(2r / 3\) result for a circle, so it sounds reasonable.

For the 2 darts problem, consider again the small area \(dA_1 = dx_1 dy_1\) at position \((x_1, y_1)\) and another small area \(dA_2 = dx_2 dy_2\) at position \((x_2, y_2)\).

The distance between these areas is \(\sqrt{\left(x_1-x_2 \right )^2 + \left(y_1-y_2 \right )^2}\) and the probability that each area is chosen by a dart is $$ P((dart\ 1\ hits\ A_1)\ and\ (dart\ 2\ hits\ A_2)) = P(dart\ 1\ hits\ A_1)\ *\ P(dart\ 2\ hits\ A_2) = \left(\frac{dA_1}{\pi r^2}\right)\left(\frac{dA_2}{\pi r^2}\right) = \frac{dx_1 dy_1 dx_2 dy_2}{\pi^2 r^4} $$

Plugging both of these into our sum (which becomes an integral in the limit) yields $$ E(D) = \frac{1}{\pi^2 r^4} \iint\iint{\sqrt{\left(x_1-x_2\right)^2 + \left(y_1-y_2\right)^2} dx_1 dy_1 dx_2 dy_2} $$

Note that if we were to fix \((x_2, y_2) = (0,0)\) at the center of the circle then we would recover the initial problem of the distance to the center:

$$ E(D) = \frac{1}{\pi^2 r^4} \iint\iint{\sqrt{\left(x_1-0\right)^2 + \left(y_1-0\right)^2} dx_1 dy_1 dx_2 dy_2} = \frac{1}{\pi^2 r^4} \left(\iint{\sqrt{x_1^2 + y_1^2} dx_1 dy_1}\right) \left(\iint{dx_2 dy_2}\right) = \frac{1}{\pi^2 r^4} \left(\iint{\sqrt{x_1^2 + y_1^2} dx_1 dy_1}\right) \left(\pi r^2\right) = \frac{1}{\pi r^2} \iint{\sqrt{x_1^2 + y_1^2} dx_1 dy_1} $$

where $$ \iint{dx_2 dy_2} = \int{dA_2} = total\ area = \pi r^2 $$

Evaluating the integral (proof left as an exercise to the reader) gives us the expected value: $$ E(D) = \frac{1}{\pi^2 r^4} \iint\iint{\sqrt{\left(x_1-x_2\right)^2 + \left(y_1-y_2\right)^2} dx_1 dy_1 dx_2 dy_2} = \frac{128r}{45 \pi} \approx 0.905r $$

Neb ◆ Saturday, 14th March 2020 at 11:54

For a proper solution to evaluating the integral over the square,

$$ E(D) = \frac{1}{4 r_0^2} \int_{-r_0}^{r_0} \int_{-r_0}^{r_0} \sqrt{x^2 + y^2}dxdy $$

Perform the same change of coordinates as with the circle, but this time with \(\theta = [0, 2\pi], r = [0, r(\theta)] \) because the value of \(r\) changes with \(\theta\). Substituting these we get:

$$ E(D) = \frac{1}{4 r_0^2} \int_{0}^{2\pi} \int_{0}^{r(\theta)} r^2 dr d\theta = \frac{1}{4 r_0^2} \int_{0}^{2\pi} \frac{(r(\theta))^3}{3} d\theta = \frac{1}{12 r_0^2} \int_{0}^{2\pi} (r(\theta))^3 d\theta $$

By the radial symmetry of the integral we can calculate its value by splitting the domain (the square) into 4 equal parts, ie along the x and y axis, and multiplying the area of any quarter by 4. By the same reasoning we can also split one of those quarters into 2 along the diagonal to form a triangle with corners at the origin, in the top right of the square, and \(r_0)\) along the x-axis, and recover the value of the integral by multiplying by 8. This triangle allows us to parameterise \(r(\theta)\) easily since we have a right angled triangle with base length \(r_0\) and angle \(\theta\) between it and the hypotenuse:

$$ r(\theta)\cos(\theta) = r_0 \implies r(\theta) = \frac{r_0}{\cos(\theta)} = r_0 \sec(\theta) $$

Plugging all of that back into the integral we get:

$$ E(D) = \left(\frac{1}{12r_0^2}\right) \left(8 \int_{0}^{\pi/4} (r(\theta))^3 d\theta \right) = \frac{2}{3r_0^2} \int_{0}^{\pi/4} r_0^3 \sec^3(\theta) d\theta = \frac{2r_0}{3} \int_{0}^{\pi/4} \sec^3(\theta) d\theta $$

We can then work through the Maths to get the result:

$$ \newline E(D) = \frac{2r_0}{3} \left [\frac{1}{2}\big( \sec(\theta)\tan(\theta) + \ln|\sec(\theta) + \tan(\theta)| \big ) \right ]_{0}^{\pi/4} \newline E(D) = \frac{r_0}{3} \bigg ( \big( \sec(\pi/4)\tan(\pi/4) + \ln|\sec(\pi/4) + \tan(\pi/4)| \big ) - \big ( \sec(0)\tan(0) + \ln|\sec(0) + \tan(0)| \big ) \bigg ) \newline E(D) = \frac{r_0}{3} \left ( \left( \sqrt{2} + \ln \left |\sqrt{2} + 1 \right| \right ) - \big ( 0 + \ln|1 + 0| \big ) \right ) \newline E(D) = \frac{r_0}{3} \left ( \sqrt{2} + \ln \left |\sqrt{2} + 1 \right| \right ) $$