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) = \sqrt{(p_1-q_1)^2 + (p_2-q_2)^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 \oplus, available in many
software libraries as hypot, the same formula can be expressed as: d(p,q) = (p_1-q_1) \oplus (p_2-q_2) = \mathsf{hypot}(p_1-q_1,p_2-q_2). It is also possible to compute the distance for points given by
polar coordinates. If the polar coordinates of p are (r,\theta) and the polar coordinates of q are (s,\psi), then their distance is d(p,q)=|p-q|.
Higher dimensions In three dimensions, for points given by their Cartesian coordinates, the distance is d(p,q)=\sqrt{(p_1-q_1)^2 + (p_2-q_2)^2 + (p_3-q_3)^2}. In general, for points given by Cartesian coordinates in n-dimensional Euclidean space, the distance is d(p,q) = \sqrt{(p_1- q_1)^2 + (p_2 - q_2)^2+\cdots+(p_n - q_n)^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 line, in the Euclidean plane • The
distance from a point to a plane in three-dimensional Euclidean space 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. == Properties ==