What this calculator does
Given two points on a plane, a handful of figures describe everything about the line between them: how far apart they are, the point exactly halfway, how steeply the line rises or falls, and the equation of the line itself. All of it comes from nothing more than the four coordinates.
Distance uses Pythagoras directly: the horizontal and vertical gaps between the points form the two legs of a right triangle, and the distance is its hypotenuse. Slope is the ratio of those same two gaps, rise over run, and is undefined rather than zero when the line is perfectly vertical.
The formula
The line equation is built from the slope and one of the two points: y = mx + c, where m is the slope and c is found by substituting a known point back in. When the run (the horizontal gap) is zero, no slope exists: the line is vertical, and its equation is simply x equal to a constant instead.
| Term | Meaning |
|---|---|
| (x₁, y₁), (x₂, y₂) | The two points. |
| Distance | √((x₂−x₁)² + (y₂−y₁)²): the straight-line gap between the points. |
| Midpoint | The point exactly halfway between them, averaging each coordinate. |
| Slope (m) | Rise over run, (y₂−y₁) ÷ (x₂−x₁): undefined for a vertical line. |
The inputs explained
| Field | What to enter |
|---|---|
| x₁ | The x-coordinate of the first point. |
| y₁ | The y-coordinate of the first point. |
| x₂ | The x-coordinate of the second point. |
| y₂ | The y-coordinate of the second point. |
When to use it
Finding the straight-line distance on a map or plan
Given two locations by their coordinates, on a site plan, a map grid or a floor layout, the distance figure is the direct line between them, not a route around obstacles.
Working out the grade or slope of a path, road or drain
Slope here is the same rise-over-run figure used for gradients, expressed as a plain ratio rather than a percentage: multiply by 100 to convert.
Finding the centre point between two locations
The midpoint is exactly halfway between the two points on both axes, useful for placing a meeting point, a support, or the centre of a span.
Writing the equation of a line through two known points
Once the slope is known, the line equation lets you find the y-value at any x along that same line, or check whether a third point lies on it.
Worked examples
Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.
Distance and slope from the origin, y fixed at 4
A point moving away from the origin along a fixed height of 4, with the horizontal distance increasing each time.
| x₂ | Distance | Slope | Angle from horizontal |
|---|---|---|---|
| 1 | 4.123 | 4.000 | 75.96° |
| 3 | 5.000 | 1.333 | 53.13° |
| 6 | 7.211 | 0.6667 | 33.69° |
| 9 | 9.849 | 0.4444 | 23.96° |
| 12 | 12.649 | 0.3333 | 18.43° |
Distance from the origin with the horizontal gap fixed at 8
The horizontal gap held at 8 while the vertical gap increases, passing through two whole-number distances.
| y₂ | Distance | Midpoint | Slope |
|---|---|---|---|
| 0 | 8.000 | (4.000, 0) | 0 |
| 3 | 8.544 | (4.000, 1.500) | 0.3750 |
| 6 | 10.000 | (4.000, 3.000) | 0.7500 |
| 9 | 12.042 | (4.000, 4.500) | 1.125 |
| 15 | 17.000 | (4.000, 7.500) | 1.875 |
Questions
How do I find the distance between two points?
Subtract the x-coordinates and the y-coordinates separately, square each difference, add them together, then take the square root: the standard Pythagorean distance formula.
Why is slope sometimes “undefined” rather than a number?
Slope is rise divided by run. When both points share the same x-coordinate, the run is zero, and dividing by zero has no defined result: the line is vertical, described by x equal to a constant instead of y = mx + c.
How do I find the midpoint between two points?
Average the two x-coordinates and average the two y-coordinates separately. The result is the point exactly halfway along the straight line joining them.
What does the angle from horizontal tell me?
It is the slope expressed as an angle instead of a ratio, found with the arctangent of rise over run. A slope of 1 corresponds to exactly 45°; a horizontal line is 0° and a vertical line is 90°.
How do I check if a third point lies on the same line?
Substitute its x-coordinate into the line equation this calculator returns. If the resulting y matches the third point’s actual y-coordinate, it lies on the line; if not, it does not.
For the diagonal of a specific rectangle rather than two arbitrary points, see the rectangle calculator. For a triangle formed by three points, use the triangle calculator.