Screenshot 2565-04-08 at 20.12.01

Finding the average distance in an equilateral triangle

In the previous post I looked at the average distance between 2 points in a rectangle.  In this post I will investigate the average distance between 2 randomly chosen points in an equilateral triangle.

Drawing a sketch.

The first step is to start with an equilateral triangle with sides 1.  This is shown above.  I sketched this using Geogebra – and used some basic Pythagoras to work out the coordinates of point C.

Screenshot 2565-04-08 at 20.15.37

I can then draw a square of sides 1 around this triangle as shown above.  I’m then going to run a Python program to randomly select points and then work out the distance between them – but I need to make sure that the 2 points chosen are both inside this triangle.  For this I need to work out the equation of the line AC and CB.

Using basic coordinate geometry we can see that the line AC has equation y = √3x.  We want the inequality y < √3x so that we are on the correct side of this line.

The line BC has equation y = -√3x + √3.  Therefore the triangle must also satisfy the inequality y < -√3x + √3.

I can then run the following code on Python, with finds the average distance between points (a,c) and (b,d) both within the unit square but also subject to the 2 inequality constraints above.

Screenshot 2565-04-08 at 20.22.08

When this is run it performs 999,999 trials and then finds the average distance.  This returns the following value:

Screenshot 2565-04-08 at 20.25.29

So we can see that the average distance is just over a third of a unit.

Finding the average distance of an equilateral triangle of length n.

Screenshot 2565-04-08 at 20.29.59

We can then draw the sketch above to find the equation of lines AC and CB for an equilateral triangle with lengths n.  This leads to the following inequalities:

 y < √3x

 y < -√3x + √3n

So we can then modify the code as follows:

Screenshot 2565-04-08 at 20.41.51

This then returns the average distances for equilateral triangles of sizes 1 to 10.

Screenshot 2565-04-08 at 20.42.08

And when we plot this on Desmos we can see that there is a linear relationship:

Screenshot 2565-04-08 at 20.45.11

The regression line has gradient 0.36 (2sf) so we can hypothesise that for an equilateral triangle of size n, the average distance between 2 points is approximately 0.36n.

Checking the maths

I then checked the actual equation for the average distance between 2 points in an equilateral triangle of sides n:

Screen Shot 2022-04-08 at 8.54.42 PM

This gives us:

Screen Shot 2022-04-08 at 8.57.43 PM

So we can see that we were accurate to 2 significant figures.  So this is a nice mixture of geometry, graphing and computational power to provide a result which would be otherwise extremely difficult to calculate.