In
geometry
Geometry (; ) is a branch of mathematics concerned with properties of space such as the distance, shape, size, and relative position of figures. Geometry is, along with arithmetic, one of the oldest branches of mathematics. A mathematician w ...
, 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
In mathematics, the Euclidean distance between two points in Euclidean space is the length of the line segment between them. It can be calculated from the Cartesian coordinates of the points using the Pythagorean theorem, and therefore is o ...
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 expression
In mathematics, an expression or equation is in closed form if it is formed with constants, variables, and a set of functions considered as ''basic'' and connected by arithmetic operations (, and integer powers) and function composition. ...
s 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
.
Formal definition
The mean line segment length for an ''n''-
dimensional shape ''S'' may formally be defined as the
expected Euclidean distance
In mathematics, the Euclidean distance between two points in Euclidean space is the length of the line segment between them. It can be calculated from the Cartesian coordinates of the points using the Pythagorean theorem, and therefore is o ...
, , ⋅, , between two random points ''x'' and ''y'',
:
where ''λ'' is the ''n''-dimensional
Lebesgue measure
In measure theory, a branch of mathematics, the Lebesgue measure, named after French mathematician Henri Lebesgue, is the standard way of assigning a measure to subsets of higher dimensional Euclidean '-spaces. For lower dimensions or , it c ...
.
For the
two-dimensional
A two-dimensional space is a mathematical space with two dimensions, meaning points have two degrees of freedom: their locations can be locally described with two coordinates or they can move in two independent directions. Common two-dimension ...
case, this is defined using the
distance formula for two points (''x''
1, ''y''
1) and (''x''
2, ''y''
2)
:
Approximation methods

Since computing the mean line segment length involves calculating multidimensional integrals, various methods for
numerical integration
In analysis, numerical integration comprises a broad family of algorithms for calculating the numerical value of a definite integral.
The term numerical quadrature (often abbreviated to quadrature) is more or less a synonym for "numerical integr ...
can be used to approximate this value for any shape.
One such method is the
Monte Carlo method
Monte Carlo methods, or Monte Carlo experiments, are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. The underlying concept is to use randomness to solve problems that might be ...
. 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 , the average distance between two points is .
Triangle
For a triangle with side lengths , , and , the average distance between two points in its interior is given by the formula
:
where
is the
semiperimeter, and
denotes
.
For an equilateral triangle with side length ''a'', this is equal to
:
Square and rectangles
The average distance between two points inside a square with side length ''s'' is
:
More generally, the mean line segment length of a rectangle with side lengths ''l'' and ''w'' is
: