---
tag: 0C95TG69SG
kind: definition
name: Euclidean distance
msc: [51N20]
defines: 0NPPGHQNXQ
uses: [0XPR1E85W0, 0XKBKGTCPC]
sources:
  - url: https://en.wikipedia.org/wiki/Euclidean_distance
    locator: Higher dimensions
---

## Definition

Let $n$ be a positive integer, and let $p = (p_1, \dots, p_n)$ and $q = (q_1, \dots, q_n)$ be points of $\mathbb{R}^n$.
The Euclidean distance between $p$ and $q$ is the real number
$$d(p, q) = \|p - q\| = \sqrt{(p_1 - q_1)^2 + (p_2 - q_2)^2 + \dots + (p_n - q_n)^2},$$
where $\|p - q\|$ is the [[length|0XKBKGTCPC]] of the vector $p - q$.

## Remarks

The function $d$ is a metric on $\mathbb{R}^n$. For all points $p$, $q$ and $r$: $d(p, q) \geq 0$, $d(p, q) = 0$ if and only if $p = q$, $d(p, q) = d(q, p)$, and $d(p, r) \leq d(p, q) + d(q, r)$.
For $n = 1$ the formula is $d(p, q) = |p - q|$.
Some applications use the squared distance $d(p, q)^2$, because it has no square root. The squared distance is not a metric, because it does not satisfy the triangle inequality.

## Explanations

### L1 human

To find the distance between two points in the plane, draw the right triangle with horizontal and vertical legs between them. The legs have lengths $|p_1 - q_1|$ and $|p_2 - q_2|$. The distance is the hypotenuse, so the Pythagorean theorem gives the formula. For $(1, 1)$ and $(4, 5)$ the distance is $\sqrt{9 + 16} = 5$.
