HomeMath › Distance Between Two Points Calculator

Distance Between Two Points Calculator

Computes the straight-line (Euclidean) distance between two points in the plane, their midpoint, the coordinate differences and the Manhattan distance.

When to use

You have two (x, y) coordinates and need the distance between them or the point halfway between them.

Do not use when: You need the slope or equation of the line through the points (use slope) or the third side of a right triangle from two sides (use pythagorean).

Formula

distance = √((x₂ − x₁)² + (y₂ − y₁)²); midpoint = ((x₁ + x₂)/2, (y₁ + y₂)/2); manhattan = |x₂ − x₁| + |y₂ − y₁|

Inputs

ParameterTypeUnitRequiredDescription
x1numberyesx-coordinate of the first point.
y1numberyesy-coordinate of the first point.
x2numberyesx-coordinate of the second point.
y2numberyesy-coordinate of the second point.

Outputs

OutputTypeUnitDescription
distancenumber√((x₂ − x₁)² + (y₂ − y₁)²).
midpoint_xnumber(x₁ + x₂) / 2.
midpoint_ynumber(y₁ + y₂) / 2.
midpointstringThe midpoint as a coordinate pair, e.g. '(2, 4)'.
delta_xnumberx₂ − x₁.
delta_ynumbery₂ − y₁.
manhattan_distancenumber|Δx| + |Δy|: the grid (taxicab) distance.

Example

(0, 0) to (3, 4): {"x1":0,"y1":0,"x2":3,"y2":4}{"distance":5,"midpoint_x":1.5,"midpoint_y":2,"midpoint":"(1.5, 2)","delta_x":3,"delta_y":4,"manhattan_distance":7}

(1, 2) to (4, 6): {"x1":1,"y1":2,"x2":4,"y2":6}{"distance":5,"midpoint_x":2.5,"midpoint_y":4,"midpoint":"(2.5, 4)","manhattan_distance":7}

GET https://tttkmbb.com/api/v1/calculate/distance-2d?x1=0&y1=0&x2=3&y2=4

Machine access

Sources

FAQ

Does the order of the points matter?

Not for the distance or midpoint. Δx and Δy are signed (second minus first), so they flip sign if the points are swapped.

Can I use this for GPS coordinates?

Only for very short distances. Latitude/longitude lie on a sphere; use the haversine formula for geographic distances.

Related calculators