Euclidean distance

From Wikipedia, the free encyclopedia
Jump to: navigation, search



The Euclidean distance between points p and q is the length of the line segment connecting them (\overline{\mathbf{p}\mathbf{q}}).


\begin{align}\mathrm{d}(\mathbf{p},\mathbf{q}) = \mathrm{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}.\end{align}







 \left\| \mathbf{p} \right\| = \sqrt{p_1^2+p_2^2+\cdots +p_n^2} = \sqrt{\mathbf{p}\cdot\mathbf{p}} ,

where the last equation involves the dot product.


The distance between points p and q may have a direction (e.g. from p to q), so it may be represented by another vector, given by

\mathbf{q} - \mathbf{p} = (q_1-p_1, q_2-p_2, \cdots, q_n-p_n)



 \left\| \mathbf{q} - \mathbf{p} \right\| = \sqrt{(\mathbf{q}-\mathbf{p})\cdot(\mathbf{q}-\mathbf{p})} .






which is equivalent to equation 1, and also to:

 \left\| \mathbf{q} - \mathbf{p} \right\| = \sqrt{ \left\| \mathbf{p} \right\|^2 + \left\| \mathbf{q} \right\| ^2 - 2 \mathbf{p}\cdot\mathbf{q}} .

One dimension[edit]

In one dimension, the distance between two points on the real line is the absolute value of their numerical difference. Thus if x and y are two points on the real line, then the distance between them is given by:

\sqrt{(x-y)^2} = |x-y|.


Two dimensions[edit]


\mathrm{d}(\mathbf{p},\mathbf{q})=\sqrt{(q_1-p_1)^2 + (q_2-p_2)^2}.

This is equivalent to the Pythagorean theorem.


\sqrt{r_1^2 + r_2^2 - 2 r_1 r_2 \cos(\theta_1 - \theta_2)}.

Three dimensions[edit]

In three-dimensional Euclidean space, the distance is

d(p, q) = \sqrt{(p_1 - q_1)^2 + (p_2 - q_2)^2+(p_3 - q_3)^2}.

n dimensions[edit]


d(p, 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[edit]


d^2(p, q) = (p_1 - q_1)^2 + (p_2 - q_2)^2+\cdots+(p_i - q_i)^2+\cdots+(p_n - q_n)^2.



See also[edit]


  • "Cluster analysis". March 2, 2011.