Euclidean distance in 2D and 3D
The Euclidean distance formula derives from the Pythagorean theorem. In 2D: d = √((x₂-x₁)² + (y₂-y₁)²). Between points (3,4) and (7,1): d = √((7-3)² + (1-4)²) = √(16+9) = √25 = 5 units.
In 3D, add the z-component: d = √((x₂-x₁)² + (y₂-y₁)² + (z₂-z₁)²). For higher dimensions (common in machine learning and data science), the same pattern extends: d = √(Σ(xi-yi)²).
Other metrics measure distance differently:
- Manhattan distance (L1 norm), computed as |x₂-x₁| + |y₂-y₁|, measures distance along grid lines — relevant for city block navigation where diagonal travel is impossible.
- Chebyshev distance (L∞ norm) takes the maximum coordinate difference, useful in chess (king moves) and warehouse robotics.