Screenshot 2565-04-11 at 16.26.00

Finding the average distance in a polygon

Over the previous couple of posts I’ve looked at the average distance in squares, rectangles and equilateral triangles.  The logical extension to this is to consider a regular polygon with sides 1.   Above is pictured a regular pentagon with sides 1 enclosed in a 2 by 2 square.  The points N and O represent 2 randomly chosen points which we find the distance between.  On average what is the distance between these randomly chosen points N and O?

Starting with a hexagon

It’s a little easier to start with a hexagon as we get some nicer coordinate points.  So, our first challenge is to find the coordinates of a regular hexagon with sides 1.  Luckily we can use the complex roots of unity to do this.  We start by finding the 6th roots of unity and then converting these to coordinates in an Argand diagram:

Screen Shot 2022-04-11 at 5.29.11 PM

This then allows us to plot the following:

Screenshot 2565-04-11 at 16.32.54

We can then work out the inequalities which define the inside of the hexagon when we generate points within the 2×2 square centred at (0,0).  This gives:

Screen Shot 2022-04-11 at 5.32.08 PM

We can then run the following code to find the average distance:

Screenshot 2565-04-11 at 16.36.25

This gives the following result:

Screenshot 2565-04-11 at 16.37.29

We can check this result as the exact value is:

Screenshot 2565-04-11 at 16.41.17

which is 0.8262589495.  So we can see we are accurate here to 3 sf.

Pentagon

For the pentagon we can find the coordinates by finding the 5th roots of unity:

Screen Shot 2022-04-11 at 5.34.33 PM

We then need to scale all coordinate points by a factor, because in a pentagon the distance from the centre to the points is not 1 (as is the case in roots of unity).  We can find the distance from the centre to the edge of a pentagon by the following trigonometry:

Screen Shot 2022-04-11 at 6.20.13 PM

So, when we scale all coordinate points by this factor we get:

Screenshot 2565-04-11 at 17.09.47

And we can then do the same method as before and run the following Python code:

Screenshot 2565-04-11 at 17.07.58

This gives:

Screenshot 2565-04-11 at 17.11.03

n-sided polygon

We can now consider an n-sided polygon with sides 1.  Let’s start with the values we’ve found for an equilateral triangle (0.364), a square (0.522), a pentagon (0.697) and a hexagon (0.826.

Screenshot 2565-04-11 at 17.14.32

When we plot these they appear to follow a linear relationship:

average distance = 0.14n

We can check that this is correct by considering the fact that an n sided polygon will approximate a circle when n gets large.  So an n sided polygon with sides length 1 can be approximated by a circle with circumference n.  This allows us to work out the radius.

Screen Shot 2022-04-11 at 5.39.09 PM

We can then substitute this into the equation for the average distance of 2 points in a circle.

Screen Shot 2022-04-11 at 5.39.47 PM

So we would expect the average distance between 2 points in a regular polygon of sides 1 to approach the equation (as n gets large):

average distance = 0.144101239n

And we’ve finished!  Everything cross-checks and works nicely.  We’ve been able to use a mixture of complex numbers, geometry, coding and trigonometry to achieve this result.