DigitHelm

Distance Calculator | 2D & 3D Points

Find Euclidean, Manhattan, and Chebyshev distance between 2D or 3D points. Includes midpoint, slope, line equation, and SVG visualization.

Quick Presets

Point 1 (P₁)

Point 2 (P₂)

All calculations are performed live in your browser, no data is sent to any server. Powered by digithelm.com.

What Is the Distance Calculator | 2D & 3D Points?

The distance formula computes the length of the straight line connecting two points in a coordinate system. It is a direct generalisation of the Pythagorean theorem: the horizontal separation Δx and vertical separation Δy form the legs of a right triangle, and the distance is its hypotenuse, d² = Δx² + Δy², therefore d = √(Δx² + Δy²).

This calculator also shows the Manhattan distance (total axis-aligned travel, like navigating city blocks) and the Chebyshev distance (the largest single-axis gap, relevant for chess king moves and robotic motion planning). For 2D points it also derives the slope, line equation, and angle of inclination.

Formula

Euclidean Distance (straight-line)
2D: d = √((x₂−x₁)² + (y₂−y₁)²)
3D: d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²)
Other distance metrics
Manhattan (L¹): d = |x₂−x₁| + |y₂−y₁| (+|z₂−z₁| for 3D)
Chebyshev (L∞): d = max(|x₂−x₁|, |y₂−y₁|) (max over all dims)
Midpoint (2D)
M = ((x₁+x₂)/2, (y₁+y₂)/2)
SymbolNameDescription
P₁Point 1(x₁, y₁) in 2D or (x₁, y₁, z₁) in 3D, the starting point
P₂Point 2(x₂, y₂) in 2D or (x₂, y₂, z₂) in 3D, the end point
Δxx-differencex₂ − x₁, horizontal displacement between the two points
Δyy-differencey₂ − y₁, vertical displacement between the two points
Δzz-differencez₂ − z₁, depth displacement in 3D space
dDistanceThe computed distance, always ≥ 0 (equals 0 only when P₁ = P₂)
MMidpointThe point equidistant from both endpoints along the segment
mSlopedy / dx, rise over run; undefined for vertical segments (Δx = 0)

How to Use

  1. 1
    Select dimensions: Choose "2D Points" for (x, y) coordinates or "3D Points" for (x, y, z) coordinates. The input fields update automatically.
  2. 2
    Try a preset: Click a quick preset, like "3-4-5 triple" or "unit diagonal", to populate the fields with a well-known example and verify the result.
  3. 3
    Enter coordinates: Type the x and y (and z for 3D) values for both points. Coordinates can be any real number, positive, negative, decimal, or zero.
  4. 4
    Press Calculate: Hit the Calculate button, or press Enter while in any input field. Results appear instantly: Euclidean, Manhattan, and Chebyshev distances, plus the midpoint, slope, and line equation (in 2D).
  5. 5
    Read the visual: In 2D mode, the diagram shows the two points connected by a solid line, with dashed lines showing Δx and Δy and a right-angle marker at the corner.
  6. 6
    Expand step trace: Click "Step-by-step trace" to see the full calculation with all intermediate values shown.
  7. 7
    Reset when done: Press Reset (or Esc) to clear all fields. Your last inputs are saved automatically and restored next time you visit.

Example Calculation

Example 1: Classic 3-4-5 triangle, P₁(0, 0) to P₂(3, 4)

Δx = 3 − 0 = 3 Δy = 4 − 0 = 4 d = √(3² + 4²) = √(9 + 16) = √25 = 5 Manhattan = |3| + |4| = 7 Chebyshev = max(3, 4) = 4 Midpoint = (1.5, 2.0) Slope = 4/3 ≈ 1.3333 · Line: y = 1.3333x

Example 2: Negative coordinates, P₁(−3, −1) to P₂(2, 3)

Δx = 2 − (−3) = 5 Δy = 3 − (−1) = 4 d = √(5² + 4²) = √(25 + 16) = √41 ≈ 6.4031 Midpoint = (−0.5, 1.0)

Example 3: 3D distance, P₁(0, 0, 0) to P₂(1, 2, 2)

Δx = 1, Δy = 2, Δz = 2 d = √(1² + 2² + 2²) = √(1 + 4 + 4) = √9 = 3 Manhattan = 1 + 2 + 2 = 5 Chebyshev = max(1, 2, 2) = 2 Midpoint = (0.5, 1.0, 1.0)

Understanding Distance | 2D & 3D Points

The Euclidean distance formula is one of the most universally applied equations in mathematics. It appears in fields as different as molecular biology, machine learning, and classical architecture, anywhere that straight-line separation between two locations or data points needs to be measured.

Euclidean, Manhattan, and Chebyshev Distance, What Is the Difference?

These three metrics all measure "distance" in a coordinate system but define it differently. Mathematically, they belong to the family of Lp norms, Euclidean is L², Manhattan is L¹, and Chebyshev is L∞ (the limit as p → ∞).

MetricFormula (2D)Physical analogy
Euclidean (L²)√(Δx²+Δy²)Straight-line flight path, "as the crow flies"
Manhattan (L¹)|Δx|+|Δy|Taxicab travel on a grid of streets, no diagonals
Chebyshev (L∞)max(|Δx|,|Δy|)Chess king moves, diagonal counts as one step
  • Euclidean is always the shortest, by the triangle inequality, the direct path is never longer than any detour.
  • Manhattan ≥ Euclidean: you always need to travel at least as far along axes as the straight-line distance.
  • Chebyshev ≤ Manhattan: it equals the longest single-axis displacement, regardless of the others.
  • In machine learning, the choice of metric changes what "nearest neighbours" means and how clusters form.

Connection to the Pythagorean Theorem

The 2D distance formula IS the Pythagorean theorem applied to coordinates. Draw a right triangle with P₁ and P₂ as the two ends of the hypotenuse. The horizontal leg has length |Δx| and the vertical leg has length |Δy|. By Pythagoras: d² = |Δx|² + |Δy|² = Δx² + Δy² (squaring removes the absolute value), so d = √(Δx² + Δy²).

The 3D formula extends this by first finding the diagonal of the base (which is a 2D distance), then applying Pythagoras again with the z-component. The result is a telescoping application of the theorem into higher dimensions.

Midpoint, Slope, and Line Equation

Between any two distinct 2D points, this calculator also derives three related quantities:

  • Midpoint M = ((x₁+x₂)/2, (y₁+y₂)/2): the point equidistant from both ends. Bisects the segment exactly in half.
  • Slope m = Δy/Δx: the rate at which y changes per unit of x. Undefined (infinite) for vertical segments. Positive slopes rise left-to-right; negative slopes fall.
  • Line equation y = mx + b: the unique infinite line through both points. The y-intercept b = y₁ − m·x₁. For vertical lines, the equation is x = x₁.

Extending to n Dimensions

The Euclidean formula generalises naturally to any number of dimensions:

d(P, Q) = √(Σᵢ (pᵢ − qᵢ)²) For vectors P = (p₁, p₂, …, pₙ) and Q = (q₁, q₂, …, qₙ)

In data science, every row in a dataset is a point in n-dimensional space where n is the number of features. The k-nearest neighbours (kNN) algorithm classifies a new point by finding the k training points with the smallest Euclidean distance. Dimensionality reduction methods like PCA try to preserve these distances while compressing the data to fewer dimensions.

Applications

  • Computer graphics: collision detection checks whether two objects are within a certain distance; ray-sphere intersection tests use the 3D distance formula.
  • Navigation and mapping: flat-map approximations use Euclidean distance for short distances, while great-circle distance (Haversine formula) corrects for Earth's curvature.
  • Machine learning: kNN, k-means clustering, support vector machines, and many other algorithms rely on distance metrics to define similarity between data points.
  • Robotics: path planning algorithms (A*, Dijkstra) use distance heuristics; joint-space distances measure how much a robot arm must move between configurations.
  • Physics: gravitational and electrostatic force both follow inverse-square laws, the force depends on 1/d², where d is the Euclidean distance between bodies.
  • Image processing: pixel-wise Euclidean distance maps are used in morphological operations and image segmentation (watershed transform, distance transform).

Frequently Asked Questions

What is Euclidean distance?

Euclidean distance is the length of the straight line connecting two points, the shortest possible path. It takes its name from Euclid of Alexandria, whose Elements established the geometry we still use today.

In 2D:

d = √((x₂−x₁)² + (y₂−y₁)²)

This is the Pythagorean theorem applied to coordinates: Δx and Δy form the legs of a right triangle, and d is the hypotenuse.

Can I use negative coordinates?

Negative coordinates are handled correctly because the formula squares the differences. d(P₁, P₂) uses (Δx)² and (Δy)², so negative Δx or Δy contribute positively to the sum.

Example: P₁(−3, −1) to P₂(2, 3):

Δx = 2−(−3) = 5, Δy = 3−(−1) = 4 d = √(25 + 16) = √41 ≈ 6.403

What is the difference between Euclidean and Manhattan distance?

Imagine navigating from one corner of a city block to the opposite corner. Euclidean distance is the diagonal shortcut. Manhattan distance is the path along the streets, go east, then north (or any axis-aligned combination).

  • Euclidean: √(Δx²+Δy²), the straight-line flight path.
  • Manhattan: |Δx|+|Δy|, total axis-aligned travel distance.
  • Chebyshev: max(|Δx|, |Δy|), like a chess king moving diagonally.
  • Euclidean ≤ Chebyshev ≤ Manhattan (by the triangle inequality).

How does this relate to the Pythagorean Theorem?

Given P₁ and P₂, draw a third point C at (x₂, y₁). The triangle P₁–C–P₂ has:

  • A right angle at C (horizontal and vertical legs meet at 90°)
  • Leg |P₁C| = |x₂−x₁| = |Δx|
  • Leg |CP₂| = |y₂−y₁| = |Δy|
  • Hypotenuse |P₁P₂| = d = √(Δx²+Δy²)

The 3D formula applies the theorem twice: first to the base (using Δx and Δy), then again with Δz.

What is the midpoint formula?

The midpoint is the arithmetic mean of the corresponding coordinates:

M = ((x₁+x₂)/2, (y₁+y₂)/2)

In 3D: M = ((x₁+x₂)/2, (y₁+y₂)/2, (z₁+z₂)/2).

The midpoint divides the segment into two equal halves. The distance from each endpoint to M equals exactly d / 2 (half the total distance).

What does the slope tell you?

Slope m = Δy / Δx = (y₂ − y₁) / (x₂ − x₁). It tells you:

  • m > 0: the line rises from left to right (positive gradient).
  • m < 0: the line falls from left to right (negative gradient).
  • m = 0: the line is perfectly horizontal (y₁ = y₂).
  • m undefined: the line is perfectly vertical (x₁ = x₂, so Δx = 0).
  • The angle to the x-axis is θ = arctan(|m|), shown in the results.

Does this calculator work in 3D?

In 3D mode, the calculator computes all three distance metrics, the midpoint, and the unit direction vector.

Example: (0,0,0) to (1,2,2):

d = √(1²+2²+2²) = √9 = 3 Manhattan = 1+2+2 = 5 Chebyshev = max(1,2,2) = 2

Slope and line equation are not defined in 3D (they require a specific plane), but the direction vector provides equivalent directional information.

Why does the calculator show multiple distance types?

The three metrics answer different questions about the same two points:

  • Euclidean: how far is the direct flight path?
  • Manhattan: how far would I travel if I can only move along grid lines?
  • Chebyshev: how many moves does a chess king need to reach the other square?

Showing all three at once helps when you are not sure which metric is appropriate for your problem, or when you need to compare the same pair of points under different assumptions.

Related Calculators