Lably
Skip to content

Euclidean distance

Length of a line segment

  • 8 min read
  • 5 chapters
  • 4 labs on Lably

Learn it on Lably

These names come from the ancient Greek mathematicians Euclid and Pythagoras. In the Greek deductive geometry exemplified by Euclid's Elements, distances were not represented as numbers but line segments of the same length, which were considered "equal". The notion of distance is inherent in the compass tool used to draw a circle, whose points all have the same distance from a common center point. The connection from the Pythagorean theorem to distance calculation was not made until the 18th century.

The distance between two objects that are not points is usually defined to be the smallest distance among pairs of points from the two objects. Formulas are known for computing distances between different types of objects, such as the distance from a point to a line. In advanced mathematics, the concept of distance has been generalized to abstract metric spaces, and other distances than Euclidean have been studied. In some applications in statistics and optimization, the square of the Euclidean distance is used instead of the distance itself.

Distance formulas

One dimension

The distance between any two points on the real line is the absolute value of the numerical difference of their coordinates, their absolute difference. Thus if p and q are two points on the real line, then the distance between them is given by:

d(p,q)=|p−q|.

A more complicated formula, giving the same value, but generalizing more readily to higher dimensions, is:

d(p,q)=(p−q)2.

In this formula, squaring and then taking the square root leaves any positive number unchanged, but replaces any negative number by its absolute value.

Two dimensions

In the Euclidean plane, let point p have Cartesian coordinates (p1,p2) and let point q have coordinates (q1,q2). Then the distance between p and q is given by:

d(p,q)=(p1−q1)2+(p2−q2)2.

This can be seen by applying the Pythagorean theorem to a right triangle with horizontal and vertical sides, having the line segment from p to q as its hypotenuse. The two squared formulas inside the square root give the areas of squares on the horizontal and vertical sides, and the outer square root converts the area of the square on the hypotenuse into the length of the hypotenuse. In terms of the Pythagorean addition operation ⊕, available in many software libraries as hypot, the same formula can be expressed as:

d(p,q)=(p1−q1)⊕(p2−q2)=hypot(p1−q1,p2−q2).

It is also possible to compute the distance for points given by polar coordinates. If the polar coordinates of p are (r,θ) and the polar coordinates of q are (s,ψ), then their distance is given by the law of cosines:

d(p,q)=r2+s2−2rscos⁡(θ−ψ).

When p and q are expressed as complex numbers in the complex plane, the same formula for one-dimensional points expressed as real numbers can be used, although here the absolute value sign indicates the complex norm:

d(p,q)=|p−q|.

Higher dimensions

In three dimensions, for points given by their Cartesian coordinates, the distance is

d(p,q)=(p1−q1)2+(p2−q2)2+(p3−q3)2.

In general, for points given by Cartesian coordinates in n-dimensional Euclidean space, the distance is

d(p,q)=(p1−q1)2+(p2−q2)2+⋯+(pn−qn)2.

The Euclidean distance may also be expressed more compactly in terms of the Euclidean norm of the Euclidean vector difference:

d(p,q)=‖p−q‖.

Objects other than points

For pairs of objects that are not both points, the distance can most simply be defined as the smallest distance between any two points from the two objects, although more complicated generalizations from points to sets such as Hausdorff distance are also commonly used. Formulas for computing distances between different types of objects include:

The distance from a point to a curve can be used to define its parallel curve, another curve all of whose points have the same distance to the given curve.

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Mathematics