Distance Calculator

Calculate the straight-line distance between two points in 2D or 3D space using the Pythagorean theorem. Useful for geometry, mapping, and physics problems.

x
x
y
y

Enter your values above to see the results.

Tips & Notes

  • Distance is always positive — squares eliminate sign. Δx=−3 gives Δx²=9 same as Δx=3.
  • Horizontal/vertical only: d = |x₂−x₁| or |y₂−y₁|. No square root needed.
  • Classic check: 3-4-5, 5-12-13, 8-15-17 are Pythagorean triples. Integer distances.
  • Midpoint is equidistant from both endpoints. Average both x and y coordinates.
  • 3D distance: add z² term under the square root. Pattern extends to any dimension.

Common Mistakes

  • Forgetting to square differences. d = √((Δx)²+(Δy)²), not √(Δx+Δy).
  • √(3²+4²) = √25 = 5, not 3+4=7. Cannot add values inside a square root.
  • Confusing Euclidean (straight-line) with Manhattan (city-block) distance.
  • Swapping x and y coordinates. Point (3,7) has x=3, y=7 — confusion changes the result.
  • 1D distance needs absolute value: |x₂−x₁|. x₂−x₁ alone can be negative.

Distance Calculator Overview

The distance between two points is one of the most fundamental measurements in mathematics and physics. In a two-dimensional coordinate plane, the straight-line Euclidean distance between any two points is derived directly from the Pythagorean theorem. Whether you are working on a geometry problem, building a map application, or analyzing data in machine learning, the distance formula appears constantly as a core building block.

The two-dimensional formula treats the horizontal and vertical separations as the two legs of a right triangle, with the straight-line distance as the hypotenuse:

d = √((x₂ − x₁)² + (y₂ − y₁)²)
EX: Points A(1, 2) and B(4, 6) → d = √((4−1)² + (6−2)²) = √(9+16) = √25 = 5
The formula works regardless of which point you label first — squaring the differences eliminates any sign issues. The three-dimensional version simply adds a third squared term under the radical:
d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²)
EX: Points (0, 0, 0) and (3, 4, 12) → d = √(9 + 16 + 144) = √169 = 13
The midpoint splits each coordinate exactly in half, landing equidistant from both endpoints:
Midpoint = ((x₁ + x₂) / 2, (y₁ + y₂) / 2)
EX: A(2, 4) and B(8, 10) → Midpoint = (5, 7)
Distance is not a single concept — different applications call for different ways of measuring how far apart two points are. Each variant below has a specific context where it outperforms the others: - Euclidean distance — straight-line, shortest possible path. The default meaning of distance in mathematics. Used in geometry, physics, and machine learning algorithms like k-nearest neighbors and k-means clustering. - Manhattan distance — sum of absolute differences: |x₂−x₁| + |y₂−y₁|. Models grid movement where only horizontal and vertical steps are allowed, like navigating city blocks. Haversine distance: — accounts for the Earth being a sphere rather than a flat plane. Essential for GPS calculations over long distances.

Frequently Asked Questions

The distance formula derives from the Pythagorean theorem. For points (x₁,y₁) and (x₂,y₂): d = √((x₂−x₁)² + (y₂−y₁)²). Example: distance from (2,3) to (7,9). Horizontal difference: 7−2=5. Vertical difference: 9−3=6. d = √(25+36) = √61 ≈ 7.81. In three dimensions: d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²). The formula works in any coordinate system — the same Pythagorean relationship holds regardless of which direction is horizontal or vertical.

Midpoint = ((x₁+x₂)/2, (y₁+y₂)/2) — the average of the coordinates. Example: midpoint of (2,3) and (8,11) = ((2+8)/2, (3+11)/2) = (5,7). In 3D: midpoint = ((x₁+x₂)/2, (y₁+y₂)/2, (z₁+z₂)/2). The midpoint divides the segment into two equal halves. To find a point that divides a segment in ratio m:n from point 1: x = (n×x₁ + m×x₂)/(m+n). For midpoint, m=n=1, which gives (x₁+x₂)/2.

Manhattan distance (L1 distance) sums the absolute differences of coordinates: d = |x₂−x₁| + |y₂−y₁|. It measures the distance traveled on a grid where only horizontal and vertical movement is allowed — like navigating city blocks. Euclidean distance (straight-line, L2) is always ≤ Manhattan distance. Manhattan distance from (2,3) to (7,9): |5|+|6|=11. Euclidean: √61≈7.81. The choice of distance metric depends on the problem — Manhattan for grid paths, Euclidean for straight-line distances.

Great-circle distance is the shortest path between two points on a sphere (Earth's surface), measured along the surface rather than through the Earth. Formula uses the haversine: a = sin²(Δlat/2) + cos(lat₁)·cos(lat₂)·sin²(Δlon/2). d = 2R·arcsin(√a) where R=6371 km. Example: New York (40.7°N, 74.0°W) to London (51.5°N, 0.1°W): great-circle distance ≈ 5,570 km. This differs from straight-line (through-Earth) distance of ≈ 5,470 km. GPS navigation uses great-circle for long routes.

In machine learning, distance metrics define similarity between data points. Euclidean distance is standard for continuous features. Cosine similarity measures the angle between vectors, ignoring magnitude — useful for text documents where frequency matters but document length should not dominate. Minkowski distance generalizes both: d = (Σ|xᵢ−yᵢ|ᵖ)^(1/p). p=1 gives Manhattan, p=2 gives Euclidean, p→∞ gives Chebyshev (maximum coordinate difference). K-nearest neighbor algorithms are entirely built on distance computations.

Distance from a point (x₀,y₀) to a line ax+by+c=0: d = |ax₀+by₀+c| / √(a²+b²). Example: distance from (3,4) to the line 2x+3y−6=0. d = |2(3)+3(4)−6| / √(4+9) = |6+12−6| / √13 = 12/√13 ≈ 3.33. This formula is used in support vector machines to find the optimal decision boundary (maximum margin classifier) and in computer graphics for checking if a point is inside or outside a region bounded by lines.