Euclidean distance




Illustration for n=3, repeated application of the Pythagorean theorem yields the formula


In mathematics, the Euclidean distance or Euclidean metric is the "ordinary" straight-line distance between two points in Euclidean space. With this distance, Euclidean space becomes a metric space. The associated norm is called the Euclidean norm. Older literature refers to the metric as the Pythagorean metric. A generalized term for the Euclidean norm is the L2 norm or L2 distance.




Contents





  • 1 Definition

    • 1.1 One dimension


    • 1.2 Two dimensions


    • 1.3 Three dimensions


    • 1.4 n dimensions


    • 1.5 Squared Euclidean distance



  • 2 See also


  • 3 References


  • 4 Further reading




Definition


The Euclidean distance between points p and q is the length of the line segment connecting them (pq¯displaystyle overline mathbf p mathbf q overlinemathbfpmathbfq).


In Cartesian coordinates, if p = (p1p2,..., pn) and q = (q1q2,..., qn) are two points in Euclidean n-space, then the distance (d) from p to q, or from q to p is given by the Pythagorean formula:[1]







d(p,q)=d(q,p)=(q1−p1)2+(q2−p2)2+⋯+(qn−pn)2=∑i=1n(qi−pi)2.displaystyle beginalignedd(mathbf p ,mathbf q )=d(mathbf q ,mathbf p )&=sqrt (q_1-p_1)^2+(q_2-p_2)^2+cdots +(q_n-p_n)^2\[8pt]&=sqrt sum _i=1^n(q_i-p_i)^2.endaligneddisplaystyle beginalignedd(mathbf p ,mathbf q )=d(mathbf q ,mathbf p )&=sqrt (q_1-p_1)^2+(q_2-p_2)^2+cdots +(q_n-p_n)^2\[8pt]&=sqrt sum _i=1^n(q_i-p_i)^2.endaligned








 



 



 



 




(1)


The position of a point in a Euclidean n-space is a Euclidean vector. So, p and q may be represented as Euclidean vectors, starting from the origin of the space (initial point) with their tips (terminal points) ending at the two points. The Euclidean norm, or Euclidean length, or magnitude of a vector measures the length of the vector:[1]


‖p‖=p12+p22+⋯+pn2=p⋅p,=sqrt p_1^2+p_2^2+cdots +p_n^2=sqrt mathbf p cdot mathbf p ,left|mathbf pright|=sqrt p_1^2+p_2^2+cdots +p_n^2=sqrt mathbf pcdot mathbf p,

where the last expression involves the dot product.


Describing a vector as a directed line segment from the origin of the Euclidean space (vector tail), to a point in that space (vector tip), its length is actually the distance from its tail to its tip. The Euclidean norm of a vector is seen to be just the Euclidean distance between its tail and its tip.


The relationship between points p and q may involve a direction (for example, from p to q), so when it does, this relationship can itself be represented by a vector, given by


q−p=(q1−p1,q2−p2,⋯,qn−pn).displaystyle mathbf q -mathbf p =(q_1-p_1,q_2-p_2,cdots ,q_n-p_n).displaystyle mathbf q -mathbf p =(q_1-p_1,q_2-p_2,cdots ,q_n-p_n).

In a two- or three-dimensional space (n = 2, 3), this can be visually represented as an arrow from p to q. In any space it can be regarded as the position of q relative to p. It may also be called a displacement vector if p and q represent two positions of some moving point.


The Euclidean distance between p and q is just the Euclidean length of this displacement vector:







‖q−p‖=(q−p)⋅(q−p).displaystyle leftleft|mathbf q-mathbf pright|=sqrt (mathbf q-mathbf p)cdot (mathbf q-mathbf p).








 



 



 



 




(2)


which is equivalent to equation 1, and also to:


‖q−p‖=‖p‖2+‖q‖2−2p⋅q.mathbf q -mathbf p rightleft|mathbf q-mathbf pright|=sqrt ^2+left.


One dimension


In the context of Euclidean geometry, a metric is established in one dimension by fixing two points on a line, and choosing one to be the origin. The length of the line segment between these points defines the unit of distance and the direction from the origin to the second point is defined as the positive direction. This line segment may be translated along the line to build longer segments whose lengths correspond to multiples of the unit distance. In this manner real numbers can be associated to points on the line (as the distance from the origin to the point) and these are the Cartesian coordinates of the points on what may now be called the real line. As an alternate way to establish the metric, instead of choosing two points on the line, choose one point to be the origin, a unit of length and a direction along the line to call positive. The second point is then uniquely determined as the point on the line that is at a distance of one positive unit from the origin.


The distance between any two points on the real line is the absolute value of the numerical difference of their coordinates. It is common to identify the name of a point with its Cartesian coordinate. Thus if p and q are two points on the real line, then the distance between them is given by:


(q−p)2=|q−p|...

In one dimension, there is a single homogeneous, translation-invariant metric (in other words, a distance that is induced by a norm), up to a scale factor of length, which is the Euclidean distance. In higher dimensions there are other possible norms.



Two dimensions




Euclidean distance in R2


In the Euclidean plane, if p = (p1p2) and q = (q1q2) then the distance is given by


d(p,q)=(q1−p1)2+(q2−p2)2.displaystyle d(mathbf p ,mathbf q )=sqrt (q_1-p_1)^2+(q_2-p_2)^2.displaystyle d(mathbf p ,mathbf q )=sqrt (q_1-p_1)^2+(q_2-p_2)^2.

This is equivalent to the Pythagorean theorem.


Alternatively, it follows from (2) that if the polar coordinates of the point p are (r1, θ1) and those of q are (r2, θ2), then the distance between the points is


r12+r22−2r1r2cos⁡(θ1−θ2).displaystyle sqrt r_1^2+r_2^2-2r_1r_2cos(theta _1-theta _2).sqrtr_1^2 + r_2^2 - 2 r_1 r_2 cos(theta_1 - theta_2).


Three dimensions


In three-dimensional Euclidean space, the distance is


d(p,q)=(p1−q1)2+(p2−q2)2+(p3−q3)2.displaystyle d(mathbf p ,mathbf q )=sqrt (p_1-q_1)^2+(p_2-q_2)^2+(p_3-q_3)^2.displaystyle d(mathbf p ,mathbf q )=sqrt (p_1-q_1)^2+(p_2-q_2)^2+(p_3-q_3)^2.


n dimensions


In general, for an n-dimensional space, the distance is


d(p,q)=(p1−q1)2+(p2−q2)2+⋯+(pi−qi)2+⋯+(pn−qn)2.displaystyle d(mathbf p ,mathbf q )=sqrt (p_1-q_1)^2+(p_2-q_2)^2+cdots +(p_i-q_i)^2+cdots +(p_n-q_n)^2.displaystyle d(mathbf p ,mathbf q )=sqrt (p_1-q_1)^2+(p_2-q_2)^2+cdots +(p_i-q_i)^2+cdots +(p_n-q_n)^2.


Squared Euclidean distance


The standard Euclidean distance can be squared in order to place progressively greater weight on objects that are farther apart. In this case, the equation becomes


d2(p,q)=(p1−q1)2+(p2−q2)2+⋯+(pi−qi)2+⋯+(pn−qn)2.displaystyle d^2(mathbf p ,mathbf q )=(p_1-q_1)^2+(p_2-q_2)^2+cdots +(p_i-q_i)^2+cdots +(p_n-q_n)^2.displaystyle d^2(mathbf p ,mathbf q )=(p_1-q_1)^2+(p_2-q_2)^2+cdots +(p_i-q_i)^2+cdots +(p_n-q_n)^2.

Squared Euclidean distance is not a metric, as it does not satisfy the triangle inequality; however, it is frequently used in optimization problems in which distances only have to be compared.


It is also referred to as quadrance within the field of rational trigonometry.



See also



  • Chebyshev distance measures distance assuming only the most significant dimension is relevant.

  • Euclidean distance matrix


  • Manhattan distance measures distance following only axis-aligned directions.


  • Minkowski distance is a generalization that unifies Euclidean distance, Manhattan distance, and Chebyshev distance.

  • Pythagorean addition


  • Haversine distance giving great-circle distances between two points on a sphere from their longitudes and latitudes.


  • Vincenty's formulae well known as "Vincent distance"


References




  1. ^ ab Anton, Howard (1994), Elementary Linear Algebra (7th ed.), John Wiley & Sons, pp. 170–171, ISBN 978-0-471-58742-2.mw-parser-output cite.citationfont-style:inherit.mw-parser-output qquotes:"""""""'""'".mw-parser-output code.cs1-codecolor:inherit;background:inherit;border:inherit;padding:inherit.mw-parser-output .cs1-lock-free abackground:url("//upload.wikimedia.org/wikipedia/commons/thumb/6/65/Lock-green.svg/9px-Lock-green.svg.png")no-repeat;background-position:right .1em center.mw-parser-output .cs1-lock-limited a,.mw-parser-output .cs1-lock-registration abackground:url("//upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Lock-gray-alt-2.svg/9px-Lock-gray-alt-2.svg.png")no-repeat;background-position:right .1em center.mw-parser-output .cs1-lock-subscription abackground:url("//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Lock-red-alt-2.svg/9px-Lock-red-alt-2.svg.png")no-repeat;background-position:right .1em center.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registrationcolor:#555.mw-parser-output .cs1-subscription span,.mw-parser-output .cs1-registration spanborder-bottom:1px dotted;cursor:help.mw-parser-output .cs1-hidden-errordisplay:none;font-size:100%.mw-parser-output .cs1-visible-errorfont-size:100%.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registration,.mw-parser-output .cs1-formatfont-size:95%.mw-parser-output .cs1-kern-left,.mw-parser-output .cs1-kern-wl-leftpadding-left:0.2em.mw-parser-output .cs1-kern-right,.mw-parser-output .cs1-kern-wl-rightpadding-right:0.2em




Further reading



  • Deza, Elena; Deza, Michel Marie (2009). Encyclopedia of Distances. Springer. p. 94.


  • "Cluster analysis". March 2, 2011.


這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto