Distance Formula Calculator
Free Distance Formula Calculator: compute Euclidean distance between two points in 2D or 3D, find the midpoint, measure total path length across multiple...
Formule utilis�e
| P₁ | P₂ | Distance | Note |
|---|---|---|---|
| (0, 0) | (3, 4) | 5 | 3-4-5 triple |
| (0, 0) | (5, 12) | 13 | 5-12-13 triple |
| (0, 0) | (8, 15) | 17 | 8-15-17 triple |
| (1, 1) | (4, 5) | 5 | Shifted 3-4-5 |
| (0, 0) | (1, 1) | √2 ≈ 1.41421 | Unit diagonal |
| (−2, −3) | (1, 1) | 5 | Negative coords |
| (0, 0) | (1, 0) | 1 | Horizontal unit |
| (2, 5) | (2, 9) | 4 | Vertical line |
| (0, 0) | (3, 3) | 3√2 ≈ 4.24264 | 45° diagonal |
| (0, 0) | (7, 24) | 25 | 7-24-25 triple |
What Is the Distance Formula? Definition and Derivation

The distance formula calculates the straight-line (Euclidean) distance between any two points in a coordinate plane. It is a direct application of the Pythagorean theorem: the distance between points P₁(x₁, y₁) and P₂(x₂, y₂) is the hypotenuse of the right triangle formed by the horizontal leg (x₂ − x₁) and the vertical leg (y₂ − y₁).
- 2D Distance Formula: d = √((x₂ − x₁)² + (y₂ − y₁)²)
- 3D Distance Formula: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)
- The formula finds the shortest possible path between two points — what we call the straight-line or Euclidean distance
- It works in any coordinate system where the axes are perpendicular (orthogonal)
Derivation from the Pythagorean theorem: If you draw a horizontal line from P₁ and a vertical line from P₂ until they meet at a right angle, you form a right triangle. The two legs have lengths |x₂ − x₁| and |y₂ − y₁|; the hypotenuse is the distance d. By the Pythagorean theorem: d² = (x₂ − x₁)² + (y₂ − y₁)², so d = √((x₂ − x₁)² + (y₂ − y₁)²).
The squaring eliminates the need for absolute values — negative differences squared always give positive results — making the formula elegant and universally applicable.
How to Use the Distance Formula Calculator
Our calculator offers five powerful computation modes:
- 2D Distance: Enter two points (x₁, y₁) and (x₂, y₂). Get the exact distance with full step-by-step working, a live SVG coordinate visualization with the connecting line and right-triangle construction, and the midpoint as a bonus result.
- 3D Distance: Add a third coordinate (z₁, z₂) to compute distances in three-dimensional space. Used in physics, engineering, and 3D graphics.
- Midpoint: Instantly find the point exactly halfway between two locations in 2D or 3D space. Formula: M = ((x₁+x₂)/2, (y₁+y₂)/2).
- Multi-Point Path: Enter up to 20 coordinate pairs (one per line as "x,y") and calculate the total path length — the sum of consecutive segment distances. Perfect for route planning, polygon perimeters, and data analysis.
- Point to Line: Calculate the perpendicular distance from a point to a line defined by two other points (or by equation ax + by + c = 0). Returns both the perpendicular foot and the distance.
All modes produce results to selectable precision (4–12 significant digits), support copy-to-clipboard, and display the full calculation breakdown.
Distance Formula Step-by-Step: Worked Examples
Understanding each step prevents errors when working by hand or verifying calculator output:
Example 1 — Basic 2D distance: Find the distance between P₁(1, 2) and P₂(4, 6).
- Step 1: Δx = x₂ − x₁ = 4 − 1 = 3
- Step 2: Δy = y₂ − y₁ = 6 − 2 = 4
- Step 3: Δx² + Δy² = 9 + 16 = 25
- Step 4: d = √25 = 5 units
- Verification: this is a 3-4-5 Pythagorean triple scaled by 1 ✓
Example 2 — Irrational result: Distance from P₁(0, 0) to P₂(3, 5).
- d = √(3² + 5²) = √(9 + 25) = √34 ≈ 5.83095 units
- Note: √34 is irrational — it cannot be expressed as a simple fraction
Example 3 — 3D distance: From A(1, 0, 2) to B(4, 3, 6).
- d = √((4−1)² + (3−0)² + (6−2)²) = √(9 + 9 + 16) = √34 ≈ 5.83095 units
Example 4 — Same x-coordinate (vertical line): From (3, 1) to (3, 7).
- d = √(0² + 6²) = √36 = 6 units
- This is simply |y₂ − y₁| when x-coordinates are equal
For precision in decimal results, our Significant Figures Calculator helps round to the correct number of significant digits.
The Midpoint Formula: Finding the Center Point
The midpoint formula finds the point M exactly halfway between P₁(x₁, y₁) and P₂(x₂, y₂):
- 2D Midpoint: M = ((x₁ + x₂)/2, (y₁ + y₂)/2)
- 3D Midpoint: M = ((x₁ + x₂)/2, (y₁ + y₂)/2, (z₁ + z₂)/2)
The midpoint is simply the arithmetic mean of each coordinate. Properties of the midpoint:
- It lies on the line segment P₁P₂, exactly halfway
- The distance from P₁ to M equals the distance from M to P₂ (both equal d/2)
- The midpoint of the hypotenuse of a right triangle is equidistant from all three vertices
- In statistics: the midpoint of a class interval is the average of its bounds, used to estimate the class mean
Midpoint example: P₁(2, 4) and P₂(8, 10) → M = ((2+8)/2, (4+10)/2) = (5, 7). Our Midpoint Calculator provides additional detail and visualization for both 2D and 3D midpoints.
3D Distance Formula and Applications

The 3D distance formula extends the Pythagorean theorem into three dimensions. For points A(x₁, y₁, z₁) and B(x₂, y₂, z₂):
- d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²)
- This is derived by applying the 2D formula twice: first find the 2D distance in the xz-plane, then treat that as one leg and y-difference as the other
- The formula generalizes to n dimensions: d = √(Σᵢ(x₂ᵢ − x₁ᵢ)²)
Key 3D applications:
- 3D graphics and game engines: Collision detection checks if d < r₁ + r₂ (sum of sphere radii) to determine if two objects overlap
- Molecular chemistry: Bond lengths between atoms in 3D crystal structures are calculated using the 3D distance formula with atomic coordinates from X-ray crystallography
- Aviation and space: Distance between aircraft at different altitudes requires the 3D formula — horizontal distance alone underestimates true separation
- Medical imaging (MRI/CT): Voxel distances in 3D scans use the 3D Euclidean metric to measure tumor sizes and lesion extents
Use our Pythagorean Theorem Calculator to explore the derivation of the 3D distance formula from the 2D theorem step by step.
Distance Metrics: Euclidean, Manhattan, and Chebyshev
The standard distance formula computes Euclidean distance — the straight-line "as the crow flies" distance. But other distance metrics are important in different contexts:
- Euclidean distance: d = √(Δx² + Δy²). The geometric straight-line distance. Used in geometry, physics, and most everyday applications. Minimized by the direct path.
- Manhattan distance (taxicab distance): d = |Δx| + |Δy|. The distance walking along city blocks — only horizontal and vertical movement allowed. Named after Manhattan's grid street layout. Used in logistics, warehousing, and pathfinding on grid maps.
- Chebyshev distance: d = max(|Δx|, |Δy|). The maximum of the coordinate differences. Models movement on a chessboard where a king can move diagonally — the king needs max(|Δrow|, |Δcol|) moves to travel between any two squares.
- Minkowski distance: d = (|Δx|ᵖ + |Δy|ᵖ)^(1/p). A generalization: p=1 gives Manhattan, p=2 gives Euclidean, p→∞ gives Chebyshev.
In machine learning, the choice of distance metric affects clustering (k-means), nearest-neighbor classification (KNN), and dimensionality reduction. Our calculator computes Euclidean distance; for the Slope Calculator, the slope m = Δy/Δx of the line segment between two points complements the distance calculation perfectly.
Point-to-Line Distance Formula
The perpendicular distance from a point P₀(x₀, y₀) to a line defined by ax + by + c = 0 is:
- d = |ax₀ + by₀ + c| / √(a² + b²)
- This is the shortest distance from the point to any point on the line
- It's perpendicular to the line — any other path would be longer
When the line is defined by two points P₁(x₁, y₁) and P₂(x₂, y₂), first compute the line equation:
- a = y₂ − y₁, b = x₁ − x₂, c = x₂y₁ − x₁y₂
- Then apply: d = |(y₂−y₁)x₀ + (x₁−x₂)y₀ + (x₂y₁−x₁y₂)| / √((y₂−y₁)² + (x₁−x₂)²)
Applications of point-to-line distance:
- Linear regression: Total sum of squared perpendicular distances is minimized by the best-fit line (though standard regression minimizes vertical distances)
- Robotics and navigation: Cross-track error — how far a robot has deviated from its planned path — is a point-to-line distance
- CAD and geometry: Checking if a point lies within tolerance of a design line
Use our Right Triangle Calculator to explore the geometry of perpendicular distances — the perpendicular from a point to a line creates a right triangle whose hypotenuse is any non-perpendicular path.
Distance Formula in Real-World Applications
- GPS and Navigation: Modern GPS systems calculate distances between coordinates using the Haversine formula, which adapts the Euclidean distance formula to a spherical surface. For small distances where Earth's curvature is negligible (under ~50 km), the flat-plane distance formula provides excellent approximations — within 0.1% of the curved geodesic distance.
- Astronomy: Stellar distances within our galaxy use the 3D distance formula with parsec coordinates. The distance from Earth to Proxima Centauri is approximately 1.295 parsecs = √(0.77² + 0.88² + 0.80²) in galactic xyz coordinates. Astronomical distance calculations use our formula as the foundation before relativistic corrections are applied.
- Computer Vision and Image Processing: Color similarity is measured as Euclidean distance in RGB space: d = √(ΔR² + ΔG² + ΔB²). Two colors with d < 30 are nearly indistinguishable to the human eye. K-means color quantization iteratively assigns pixels to the nearest cluster centroid using this metric.
- Architecture and Civil Engineering: Calculating run-rise ratios for ramps, staircase spans, and structural diagonal members all reduce to distance formula calculations. A ramp with horizontal run 12 m and vertical rise 1 m has actual length √(144 + 1) = √145 ≈ 12.04 m.
For circular applications where distance from a center determines inclusion (d < r means inside the circle), see our Circumference Calculator — the circle itself is the set of all points at fixed distance r from the center.
Related Calculators
- Midpoint Calculator — The midpoint between two points divides the distance exactly in half: M = ((x₁+x₂)/2, (y₁+y₂)/2). If you know the distance d between P₁ and P₂ and find the midpoint M, then d(P₁, M) = d(M, P₂) = d/2 exactly. Our Midpoint Calculator extends this with section formula (dividing in any ratio m:n) for both 2D and 3D space.
- Slope Calculator — The slope of the line connecting P₁(x₁,y₁) to P₂(x₂,y₂) is m = (y₂−y₁)/(x₂−x₁) = Δy/Δx. Since distance uses Δx and Δy, slope and distance are complementary: together they fully characterize the line segment connecting two points. The angle θ = arctan(m) and d = √(Δx²+Δy²) give the polar form of the segment.
- Pythagorean Theorem Calculator — The distance formula is the Pythagorean theorem applied to coordinate geometry. If Δx = 3 and Δy = 4, then d = √(3²+4²) = 5 — this is the classic 3-4-5 Pythagorean triple. The Pythagorean theorem calculator verifies every step of the proof and finds all Pythagorean triples for integer distances.
- Right Triangle Calculator — The right triangle formed by Δx (horizontal leg), Δy (vertical leg), and d (hypotenuse) is solved completely by the Right Triangle Calculator. It returns both acute angles: θ₁ = arctan(Δy/Δx) gives the bearing angle of the segment, and θ₂ = 90° − θ₁ completes the triangle.
- Circumference Calculator — A circle is defined as the locus of all points at fixed distance r from a center point — the distance formula computes whether any given point is exactly on (d=r), inside (d<r), or outside (d>r) the circle. The circumference C = 2πr and area A = πr² both use the same radius that appears in the distance equation d = r.