Mathwords logoReference LibraryMathwords

Euclidean Distance

Euclidean distance is the straight-line distance between two points. It works in two dimensions, three dimensions, or even higher — it's the most common way to measure how far apart two points are.

Euclidean distance is the length of the line segment connecting two points in nn-dimensional Euclidean space. It generalizes the Pythagorean theorem: for two points p\mathbf{p} and q\mathbf{q} with nn coordinates each, the Euclidean distance is the square root of the sum of squared differences across all coordinates. In two dimensions, this reduces to the familiar distance formula from coordinate geometry.

Key Formula

d(p,q)=i=1n(qipi)2d(\mathbf{p}, \mathbf{q}) = \sqrt{\sum_{i=1}^{n}(q_i - p_i)^2}
Where:
  • d(p,q)d(p, q) = the Euclidean distance between points p and q
  • nn = the number of dimensions (coordinates)
  • pip_i = the i-th coordinate of point p
  • qiq_i = the i-th coordinate of point q

Worked Example

Problem: Find the Euclidean distance between the points p=(1,3,2)\mathbf{p} = (1, 3, 2) and q=(4,7,2)\mathbf{q} = (4, 7, 2) in 3D space.
Step 1: Subtract each coordinate of p from the corresponding coordinate of q.
(41,  73,  22)=(3,  4,  0)(4 - 1,\; 7 - 3,\; 2 - 2) = (3,\; 4,\; 0)
Step 2: Square each of those differences.
32=9,42=16,02=03^2 = 9, \quad 4^2 = 16, \quad 0^2 = 0
Step 3: Add the squared differences together.
9+16+0=259 + 16 + 0 = 25
Step 4: Take the square root of the sum.
d=25=5d = \sqrt{25} = 5
Answer: The Euclidean distance between (1,3,2)(1, 3, 2) and (4,7,2)(4, 7, 2) is 55.

Visualization

Why It Matters

Euclidean distance is the default distance metric in many machine learning and data science algorithms. Clustering methods like k-means group data points by measuring Euclidean distances between them and cluster centers. It also appears in computer graphics for collision detection, in recommendation systems for comparing user preferences, and throughout physics whenever straight-line distance matters.

Common Mistakes

Mistake: Forgetting to take the square root at the end
Correction: Without the square root, you get the squared Euclidean distance, which is a different (though sometimes useful) quantity. Always finish with x\sqrt{\phantom{x}} to get the actual distance.
Mistake: Subtracting coordinates in the wrong order across dimensions
Correction: Stay consistent: subtract pip_i from qiq_i (or vice versa) for every coordinate. Since the differences are squared, the order within a single subtraction doesn't affect the result, but mixing up which point's coordinates you use will give wrong differences.

Related Terms