Skip to the calculator
Rule Calculator

Distance Formula Calculator

With x₁ 1, y₁ 2, x₂ 4, y₂ 6, distance formula comes to 5.000000 — distance. It is reached in 8 steps, the last of which is sqrt(squares), and each one is printed on the page with its numbers filled in. The formula is the one published by Wolfram MathWorld, not an approximation fitted to it.

Distance between two points in the plane or in space, with the midpoint and the slope, and every step of the square root shown.

By Alex Seote, Built and maintains Rule Calculator · Formula and sources checked · How we check

Points in The plane — x and y, x₁ 1, y₁ 2, x₂ 4

5.000000

Distance for the example below. Editing a field recomputes the calculator below; this figure holds the answer the page was loaded with.

It is written into the HTML rather than drawn by a script, so a search engine reading this page without running JavaScript still finds an answer.

Distance
5.000000
x₂ − x₁
x2 - x13
y₂ − y₁
y2 - y14
z₂ − z₁
z2 - z10
The squares, added
pow(dx, 2) + pow(dy, 2) + pow(dz, 2)25
Distance
sqrt(squares)5
Midpoint x
(x1 + x2) / 22.5
Midpoint y
(y1 + y2) / 24
Slope between the points
dx == 0 ? 0 : dy / dx1.333

Ask about this in the chat

Worked example

From (1, 2) to (4, 6) the differences are 3 and 4, their squares are 9 and 16, and the root of 25 is exactly 5. It is the 3-4-5 triangle, which is the same reason a builder uses those three numbers to square a corner.

How to work it out yourself

  1. 1.Subtract the two x values and the two y values. The order does not matter — squaring removes the sign.
  2. 2.Square each difference and add them. In three dimensions the z difference joins the same sum.
  3. 3.Take the square root. The midpoint needs no root at all: it is just the average of each coordinate.

The formula

  1. x₂ − x₁x2 - x1
  2. y₂ − y₁y2 - y1
  3. z₂ − z₁z2 - z1
  4. The squares, addedpow(dx, 2) + pow(dy, 2) + pow(dz, 2)
  5. Distancesqrt(squares)
  6. Midpoint x(x1 + x2) / 2
  7. Midpoint y(y1 + y2) / 2
  8. Slope between the pointsdx == 0 ? 0 : dy / dx

Source: Wolfram MathWorld — distance

Questions people actually ask

Does it matter which point I call the first?
No. Swapping them flips the sign of both differences, and squaring throws the sign away, so the distance is identical. The slope is unchanged too, for the same reason. Only the midpoint is order-free by construction — it is the average either way.
Why is the distance formula the Pythagorean theorem?
Because it is. Drop a horizontal and a vertical line from the two points and you have a right triangle whose legs are the x difference and the y difference; the distance is its hypotenuse. In three dimensions the same argument runs twice, which is why the z term joins the sum rather than needing anything new.
What is the slope when the points are stacked vertically?
Undefined, not zero. A vertical line has no run to divide by, and a slope of zero means the opposite — a flat line. This calculator prints zero in that case because it has to print something; the honest reading is that the slope does not exist, and the two x values being equal is the tell.
How do I find the distance from a point to the origin?
Put zeros in the second point. The formula then reduces to the square root of x² + y², which is the length of the position vector. It is also what a hypotenuse calculator answers with the legs set to your coordinates.

Related

Put this calculator on your site

Free, no attribution required beyond the link.

<iframe src="https://rulecalculators.com/embed/distance-formula" width="100%" height="420" style="border:1px solid #e7e4de;border-radius:12px" title="Distance Formula Calculator"></iframe>
Did this answer your question?