In geometry, the mean line segment length is the average length of a line segment connecting two points chosen uniformly at random in a given shape. In other words, it is the expected Euclidean distance between two random points, where each point in the shape is equally likely to be chosen. Even for simple shapes such as a square or a triangle, solving for the exact value of their mean line segment lengths can be difficult because their closed-form expressions can get quite complicated. As an example, consider the following question:
What is the average distance between two randomly chosen points inside a square with side length 1? While the question may seem simple, it has a fairly complicated answer; the exact value for this is 2 + 2 + 5 ln ( 1 + 2 ) 15 {\displaystyle {\frac {2+{\sqrt {2}}+5\ln(1+{\sqrt {2}})}{15}}} .
Formal definition The mean line segment length for an n-dimensional shape S may formally be defined as the expected Euclidean distance ||⋅|| between two random points x and y,
E [ ‖ x − y ‖ ] = 1 λ ( S ) 2 ∫ S ∫ S ‖ x − y ‖ d λ ( x ) d λ ( y ) {\displaystyle \mathbb {E} [\|x-y\|]={\frac {1}{\lambda (S)^{2}}}\int _{S}\int _{S}\|x-y\|\,d\lambda (x)\,d\lambda (y)}
where λ is the n-dimensional Lebesgue measure. For the two-dimensional case, this is defined using the distance formula for two points (x1, y1) and (x2, y2)
1 λ ( S ) 2 ∬ S ∬ S ( x 1 − x 2 ) 2 + ( y 1 − y 2 ) 2 d x 1 d y 1 d x 2 d y 2 . {\displaystyle {\frac {1}{\lambda (S)^{2}}}\iint _{S}\iint _{S}{\sqrt {(x_{1}-x_{2})^{2}+(y_{1}-y_{2})^{2}}}\,dx_{1}\,dy_{1}\,dx_{2}\,dy_{2}.}
Approximation methods
Since computing the mean line segment length involves calculating multidimensional integrals, various methods for numerical integration can be used to approximate this value for any shape. One such method is the Monte Carlo method. To approximate the mean line segment length of a given shape, two points are randomly chosen in its interior and the distance is measured. After several repetitions of these steps, the average of these distances will eventually converge to the true value. These methods can only give an approximation; they cannot be used to determine its exact value.
Formulas
Line segment For a line segment of length d, the average distance between two points is 1/3d.
Triangle For a triangle with side lengths a, b, and c, the average distance between two points in its interior is given by the formula
… excerpt ends here. Continue reading the full article.

