How to use this calculator
- 1 Choose 2D for points on a flat plane, or 3D for points in space.
- 2 Enter the x and y coordinates of the first and second point. In 3D, also enter the z coordinates.
- 3 Read the distance, the midpoint and the change in each coordinate. The slope appears in 2D.
- 4 Check the working line to see the formula the calculator used.
What is a coordinate?
A coordinate tells you where a point sits. On a flat graph, you use two numbers, written as (x, y). The x number tells you how far to go across, and the y number tells you how far to go up.
In 3D, you add a third number, z, for height or depth. So a point written as (2, 5, 1) sits 2 units across, 5 up and 1 out from the origin.
The origin is the point (0, 0) in 2D, or (0, 0, 0) in 3D. Every other point is measured from there.
How the distance is found
The distance between two points is the length of the straight line joining them. To find it, first work out the change in each coordinate. Subtract the first point’s x from the second point’s x, and do the same for y.
Next, square each change, add the squares, and take the square root. This is the distance formula. It is built on the Pythagorean theorem, because the changes form the two short sides of a right triangle.
In 3D, you do the same with three changes instead of two. For example, a drone that moves 3 m across, 4 m forward and 12 m up has travelled √(9 + 16 + 144) = 13 m in a straight line. You can check each step with the Pythagorean theorem calculator.
| Points | Changes (Δx, Δy) | Distance |
|---|---|---|
| (0, 0) and (3, 4) | 3, 4 | 5 |
| (1, 2) and (4, 6) | 3, 4 | 5 |
| (−3, −1) and (2, 11) | 5, 12 | 13 |
| (0, 0) and (1, 1) | 1, 1 | √2 ≈ 1.4142 |
Midpoint and slope
The midpoint is the point exactly halfway between the two points. You find it by averaging each coordinate. Add the two x values and divide by two, then do the same for y.
The slope tells you how steep the line is. It is the change in y divided by the change in x, often called rise over run. A slope of 2 means the line rises 2 units for every 1 unit it moves across.
A line that is perfectly upright has no slope, because its change in x is zero and you cannot divide by zero. The calculator shows this as undefined. To explore lines further, try the slope calculator.
Limits of this calculator
This calculator measures straight lines on a flat plane, or in ordinary 3D space. It treats each unit as the same length in every direction, and it does not use map or GPS data.
So it is not a tool for the distance between two cities. Those points lie on the curved surface of the Earth, which needs a different method. Use it for graphs, drawings, models and homework.
For right triangles with two known sides, the right triangle calculator finds the third side and the angles.
The formula
Distance in 2D
d = √((x₂ − x₁)² + (y₂ − y₁)²)
- x₁, y₁
- coordinates of the first point
- x₂, y₂
- coordinates of the second point
Distance in 3D
d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)
- z₁, z₂
- the height or depth coordinate of each point
Midpoint
M = ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2, (z₁ + z₂) ÷ 2)
- M
- the point halfway between the two points
Slope (2D only)
m = (y₂ − y₁) ÷ (x₂ − x₁)
- m
- rise over run; undefined when x₁ = x₂
Worked example
The points (−3, −1) and (2, 11) on a flat plane
- 1.Change in x: 2 − (−3) = 5. Change in y: 11 − (−1) = 12.
- 2.Distance: √(5² + 12²) = √(25 + 144) = √169 = 13.
- 3.Midpoint: ((−3 + 2) ÷ 2, (−1 + 11) ÷ 2) = (−0.5, 5).
- 4.Slope: 12 ÷ 5 = 2.4.
The points are 13 units apart. Their midpoint is (−0.5, 5) and the line through them has a slope of 2.4.
Frequently asked questions
How do I calculate the distance between two points?
Subtract the x values and the y values to get the two changes. Square each change, add them, and take the square root. For (0, 0) and (3, 4), the distance is √(9 + 16) = 5.
Why is the distance formula based on the Pythagorean theorem?
The changes in x and y form the two legs of a right triangle. The straight line between the points is its hypotenuse. In 3D, the same idea is applied with one more change.
What does an undefined slope mean?
When the two points share the same x value, the line is vertical. Dividing by a change of zero is not possible, so the slope is undefined.
Does the order of the two points matter?
No. Swapping the points changes the sign of each change, but squaring removes the sign. So the distance and the midpoint stay the same.
Can I use this calculator for distance on a map?
Not for real map distances. This tool measures a straight line on a flat plane. Distances between latitude and longitude points on the Earth need a different method.
Sources
Last reviewed by the GridCalculators team.