Unit Square

What is the average distance between two points inside the unit square? The picture shows TwoPoints20 pairs of random points, shown as the endpoints of straight line segments.

 

Think of x and y as lengths of average intervals in the unit interval and think of two opposite vertices of a rectangle with sides x and y.

TwoPoints2

Then x\approx 1/3 and y\approx 1/3 and hence the average distance should be about

    \begin{equation*} \frac{1}{3}\sqrt{2}\approx 0.471\, \end{equation*}

or a bit less than 1/2.

Here are the results of an experiment with 1000\,000 trials repeated 10 times:

    \begin{equation*} \begin{array}{ccccc} 0.52110264 & 0.52117954 & 0.52178246 & 0.52110682 & 0.52139738 \\ 0.52183945 & 0.52150993 & 0.52167014 & 0.52187251 & 0.52157608% \end{array} \end{equation*}

Let x be difference in there first coordinates and y the difference in their second coordinates. The larger first coordinate can be chosen anywhere in an interval of length 1-x, and the larger second coordinate can be chosen anywhere in an interval of length 1-y.

TwoPoints3

The probability of picking a rectangle of this size and shape should be proportional to the area \left( 1-x\right) \left( 1-y\right) of the red rectangle.

The distance between the two endpoints is \sqrt{x^{2}+y^{2}}. The average distance is

    \begin{eqnarray*} \frac{\int_{0}^{1}\int_{0}^{1}\sqrt{x^{2}+y^{2}}\left( 1-x\right) \left( 1-y\right) \,dy\,dx}{\int_{0}^{1}\int_{0}^{1}\left( 1-x\right) \left( 1-y\right) \,dy\,dx} &=&\frac{ \frac{1}{12}\ln \left( \sqrt{2} +1\right) +\frac{1}{60}\sqrt{2}+\frac{1}{30}}{\frac{1}{4}} \\ &=&0.521\,405\,433\, 2 \end{eqnarray*}

We could make this a bit more ugly by taking two points \left( x,y\right) and \left( u,v\right) in the unit square and evaluating

    \begin{equation*} \frac{\int_{0}^{1}\int_{0}^{1}\int_{0}^{1}\int_{0}^{1}\sqrt{\left( x-u\right) ^{2}+\left( y-v\right) ^{2}}\,dx\,dy\,du\,dv}{\int_{0}^{1} \int_{0}^{1}\int_{0}^{1}\int_{0}^{1}\,dx\,dy\,du\,dv}=\int_{0}^{1} \int_{0}^{1}\int_{0}^{1}\int_{0}^{1}\sqrt{\left( x-u\right) ^{2}+\left( y-v\right) ^{2}}\,dx\,dy\,du\,dv \end{equation*}

See http://mathworld.wolfram.com/SquareTrianglePicking.html for more details.