Problem (Credit: R Muthu Veerappan)
If we pick a random point from a regular polygon, what will be the expected distance of the point from the centre assuming that the circu mradius of the polygon is ?
Solution
Choosing random points in a triangle
To compute the expected distance, using symmetry it is easy to see that we only need to consider the points in a right angled triangle triangle with one vertex at the centre of the regular polygon, one vertex coinciding with the vertex of the polygon and the other one at the midpoint of the edge of the polygon.
If is the centre of the regular polygon and the circu radius is one unit, we can always orient the polygon so that the right angled triangle that we wish to draw the random points from have the vertices and
In the figure below, when the regular polygon is an equilateral triangle, we draw the random points from .
Analytical computation of expected value
We need to evaluate the integral
For the substitution, and , the Jacobian is given by
The above integral reduces to
The following result which can be easily obtained by using integration by parts was used in the evaluation of the above integral
For , the expected value is given by .
For , the expected value is given by .
Computational Verification
Randomly choosing points in a triangle
There are three well known methods to allow one to uniformly random sample from a triangle. These are:
- The Parallelogram method
- The Kraemer Method
- Inverse cumulative distribution method
The Parallelogram method
The parallelogram method is as follows.
For a triangle , consider the parallelogram .
For a point in the unit square , define the point such that .
This point will always fall inside the parallelogram. However, if it occurs in the complementary triangle , then we can either reject the point or reflect it back into the triangle . That is if , then , but if , then .
Kraemer Method
Suppose we have an arbitrary triangle with vertices , , and . In this method, we choose two random numbers in , and . Let , the point is a random point within the triangle .
Here is a plot of the random points obtained in an equilateral triangle whose median lies on the -axis.
Inverse cumulative distribution method
Suppose we have an arbitrary triangle with vertices , , and . In this method, we choose two random numbers and in and a point such that .
is a random point within the triangle .Intuitively, sets the percentage from vertex to the opposing edge, while represents the percentage along that edge. Taking the square-root of gives a uniform random point with respect to surface area.
Python code to calculate expected distance
import numpy as np
from math import sqrt
import numpy as np
from math import sqrt
def kraemer_points_on_triangle(v, n):
x = np.sort(np.random.rand(2, n), axis=0)
return np.column_stack([x[0], x[1]-x[0], 1.0-x[1]]) @ v
runs = 1000000
#n=3
v = np.array([(0, 0), (0.5, 0), (0.5, sqrt(3)/2)])
points = kraemer_points_on_triangle(v, runs)
print(np.mean(np.sqrt(np.square(points).sum(axis=1))))
#n=4
v = np.array([(0, 0), (0,1/sqrt(2)), (1/sqrt(2), 1/sqrt(2))])
points = kraemer_points_on_triangle(v, runs)
print(np.mean(np.sqrt(np.square(points).sum(axis=1))))
As expected, the expected value from the simulation matches the result that was calculated analytically 😊.