You choose a random point, uniformly, within a regular hexagon, with unit side length.
What's the average distance to the six sides?
Program output: 1.1077388342288856
This could be calculated by taking the double integral
as x goes from 0 to 1/2, y goes from 0 to √3x of the distance formula
plus the double integral
as x goes from 1/2 to 1, y goes from 0 to √3(1-x) of the distance formula
The program below does the equivalent of numeric integration of the above.
wlog, the points are limited to the first equilateral triangle in the first quadrant,
which has vertices (0,0), (1,0), (.5,√3/2).
Every point from (0,0) to (1,1) is considered but those outside this triangle are ignored.
--------------
s = 3**.5
t = (3**.5)/2
vertices = [[1,0],[.5,t],[-.5,t],[-1,0],[-.5,-t],[.5,-t]]
mesh = 1000
grid = [(i+.5)/(mesh) for i in range(mesh)]
distances = []
for x in grid:
for y in grid:
if y > s*x:
continue
if y > s*(1-x):
continue
ddist = 0
for v in vertices:
ddist += ((v[0]-x)**2 + (v[1]-y)**2)**.5
distances.append(ddist/6)
print(sum(distances)/len(distances))
|
Posted by Larry
on 2023-10-25 13:00:12 |