Last verified · v1.0
Calculator · math
Euclidean Distance Calculator
Compute straight-line distance between two points in 2D, 3D, or 4D space using the Euclidean distance formula d = √∑(qᵢ − pᵢ)².
Inputs
Euclidean Distance
—
Explain my result
Get a plain-English breakdown of your result with practical next steps.
The formula
How the
result is
computed.
What Is Euclidean Distance?
Euclidean distance is the straight-line distance between two points in any number of dimensions. Named after the ancient Greek mathematician Euclid, it represents the shortest path connecting two locations through space — the as-the-crow-flies measurement most people intuitively picture when they think of distance. This metric forms the backbone of analytic geometry and powers algorithms across data science, computer graphics, robotics, and physics.
The Euclidean Distance Formula
The general formula for n-dimensional Euclidean distance between points P(p₁, p₂, …, pₙ) and Q(q₁, q₂, …, qₙ) is:
d = √∑(qᵢ − pᵢ)² for i = 1 to n
The formula squares each coordinate difference to eliminate negative values, sums those squared differences, then extracts the square root to yield the actual distance. According to Stanford's n-Dimensional Euclidean Distance reference, this generalization holds consistently across 2D, 3D, and arbitrarily higher-dimensional spaces without modification to its logic.
2D Distance Formula
For two points P(x₁, y₁) and Q(x₂, y₂) in a flat plane:
d = √((x₂ − x₁)² + (y₂ − y₁)²)
This is a direct application of the Pythagorean theorem. The horizontal separation (x₂ − x₁) and vertical separation (y₂ − y₁) form the two legs of a right triangle, and the distance is the hypotenuse. As Khan Academy's analytic geometry series demonstrates, this geometric derivation makes the formula intuitive rather than merely memorized.
3D Distance Formula
Adding a z-axis extends the formula to three-dimensional space. For P(x₁, y₁, z₁) and Q(x₂, y₂, z₂):
d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)
4D Distance Formula
In four-dimensional space — relevant to physics (spacetime) and machine learning (feature spaces) — a fourth coordinate w is added:
d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)² + (w₂ − w₁)²)
Worked Example: 2D
Find the distance between A(3, 4) and B(7, 1):
- x-difference: 7 − 3 = 4; squared: 16
- y-difference: 1 − 4 = −3; squared: 9
- Sum of squares: 16 + 9 = 25
- Square root: √25 = 5 units
Worked Example: 3D
Find the distance between P(1, 2, 3) and Q(5, 5, 3):
- Differences: (5−1) = 4, (5−2) = 3, (3−3) = 0
- Squares: 16 + 9 + 0 = 25
- Result: √25 = 5 units
Real-World Applications
- Navigation and GPS: Mapping tools compute straight-line distances between geographic coordinates for route estimation and proximity searches.
- Machine learning: K-nearest neighbors (KNN) and K-means clustering rank and group data points by their Euclidean distance in feature space.
- Computer graphics and game engines: Collision detection, lighting attenuation, and object-proximity checks rely on 3D Euclidean distance between vertices and camera positions.
- Robotics and autonomous vehicles: Path-planning algorithms minimize cumulative Euclidean distance across waypoints to find efficient trajectories.
- Bioinformatics: Researchers measure similarity between gene expression profiles as Euclidean distance in high-dimensional feature space.
Important Considerations
Euclidean distance assumes all dimensions share the same scale and unit. When variables differ in magnitude — such as mixing age in years with income in dollars — dimensions with larger values dominate the result. Normalizing features before computation or switching to Mahalanobis distance corrects this imbalance. As detailed in Euclidean Distance Geometry and Applications (UC Davis), high-dimensional spaces also exhibit the curse of dimensionality, where pairwise distances converge and lose discriminatory power above roughly 10 to 20 dimensions.
Reference