2D Distance Calculator
Find the distance, midpoint, slope and direction between two points on an interactive coordinate plane.
Quick Answer
The straight-line distance is √(Δx² + Δy²), where Δx and Δy are the horizontal and vertical changes between the points.
Calculate the distance
Straight-line distance
- Midpoint
- (2.5,
4) - Slope
- 1.33333333
- Direction A → B
- 53.1301024°Line inclination 53.1301024°
- Manhattan distance
- 7
Show the calculation
- Horizontal change Δx = x₂ − x₁ = 3
- Vertical change Δy = y₂ − y₁ = 4
- Straight-line distance d = √(Δx² + Δy²) → 5
- A
- (1,
2) - B
- (4,
6) - M
- (2.5,
4)
Coordinates and units
On a Cartesian plane, each point has an ordered pair (x, y). The x-coordinate gives the horizontal position and the y-coordinate gives the vertical position. The axes cross at the origin (0, 0) and divide the plane into four quadrants.
Euclidean distance measures the length of the straight segment between the points. It is positive for distinct points and zero for identical points. Use the same length unit for both axes.
Distance formula and proof
Write the signed changes from A to B as Δx = x₂ − x₁ and Δy = y₂ − y₁. These changes follow the direction you travel along each axis.
Build the right triangle
- Draw a horizontal leg from A(x₁, y₁) to C(x₂, y₁).
- Join C to B(x₂, y₂) with a vertical leg. The leg lengths are |Δx| and |Δy|.
- Apply the Pythagorean theorem to the hypotenuse AB. Square each leg, add the squares, then take the nonnegative square root.
Moving both points by the same amount preserves both coordinate changes, so it preserves their distance.
Midpoint
The midpoint is halfway along the segment. Move from A by half the horizontal change and half the vertical change. This gives the average of the x-coordinates and the average of the y-coordinates.
Use the midpoint to locate the center between two endpoints or to split a segment into two equal lengths.
Slope and direction
Slope measures vertical change per unit of horizontal change. For Δx ≠ 0, m = Δy ÷ Δx. Horizontal segments have slope zero, and vertical segments have undefined slope.
Direction angle and line inclination
The direction from A to B uses atan2(Δy, Δx) in degrees from the positive x-axis. Counterclockwise angles are positive. Line inclination treats both travel directions as the same line and uses an angle from 0° up to 180°. A vertical line has 90° inclination.
If the points coincide, there is no unique direction or line through them. Both the slope and angle are undefined.
Manhattan distance
For a shortest path restricted to horizontal and vertical moves, add the lengths of the two legs. Manhattan distance is |Δx| + |Δy|. It equals the straight-line distance when the two points share a row or column.
Chebyshev distance counts the minimum steps on a square grid when a horizontal, vertical or diagonal move each takes one step. It is the greater of |Δx| and |Δy|.
Worked examples
A 3–4–5 triangle
From A(1, 2) to B(4, 6), the changes are 3 and 4. The two squares add to 25, so the distance is 5 units.
Points in different quadrants
From A(−3, −4) to B(2, 8), subtracting the negative coordinates gives changes of 5 and 12. Then d = √(25 + 144) = 13.
Distance from the origin
The origin is (0, 0), so the legs to (7, 24) have lengths 7 and 24. Then d = √(49 + 576) = 25.
Distance, midpoint and slope together
For A(−2, 3) and B(6, −1), the changes are 8 and −4. Distance is √80 = 4√5 ≈ 8.944, midpoint is (2, 1), and slope is −4 ÷ 8 = −0.5. The A-to-B angle is about −26.57°.
Find a missing coordinate
Suppose A(2, 5) is 10 units from B(10, y). Squaring the distance gives 100 = 64 + (y − 5)². The vertical change has magnitude 6, so B can have y = 11 or y = −1.
Extending the formula to 3D
For points with x, y and z coordinates, include the squared change on the z-axis before taking the square root.
The same pattern works in higher dimensions. Find each coordinate difference, square it, add all the squares, then take the square root.
Where the distance formula is used
- Maps and GIS. Use Cartesian distance for projected coordinates measured in the same length unit. Raw latitude and longitude are angles, so Earth-surface distances use a geographic distance method. Use the map distance and scale calculator for measurements on a scaled map.
- Computer graphics. Compare the distance between two circles’ centers with the sum of their radii to detect contact.
- Robotics. Estimate the straight-line gap to a waypoint while planning a path around obstacles.
- Machine learning. Compare the distance between feature vectors after choosing suitable feature scales.
- Site planning. Find diagonal spans when both axes use the same scale on a plan.
- Physics. Find displacement magnitude from horizontal and vertical changes. Gravitational force between two masses also depends on the distance between their centers.
- Medical imaging. Use calibrated pixel or voxel spacing to convert coordinates to physical lengths.
- Sports analytics. Sum distances between successive tracking points to estimate a player’s path length.
Common mistakes
- Square the differences separately. For changes 3 and 4, the squared distance is 9 + 16 = 25.
- Take the final square root. The squared distance is in square units. The square root gives the length in the original unit.
- Use parentheses for a negative number. For example, 2 − (−3) = 5.
- Identify the quantity requested. Displacement is the vector of changes. Its length is the straight-line distance.
- Check the horizontal change before dividing. If x₁ = x₂, leave slope undefined.
- Average coordinates axis by axis. Pair the two x-values and then pair the two y-values.
Integer distances and related tools
Common Pythagorean triples
| Horizontal leg | Vertical leg | Distance |
|---|---|---|
| 3 | 4 | 5 |
| 5 | 12 | 13 |
| 8 | 15 | 17 |
| 7 | 24 | 25 |
| 9 | 40 | 41 |
For circles, see the diameter calculator and circumference calculator. Find more practice in the homework resources.
Practice and background
Crossing a coordinate axis
Move from the point (−2, 3) to (4, −5). The horizontal change is six and the vertical change is minus eight. Squaring those changes gives 36 and 64. The square root of their sum is ten. Walking along the grid edges would cover fourteen units, a different path.
Frequently asked questions
What changes when I swap A and B?
Both coordinate changes reverse sign. The distance, midpoint, slope, line inclination and Manhattan distance stay the same. For distinct points, the direction of travel reverses by 180°.
How do I express a clockwise direction as a positive angle?
Add 360° to a negative direction. For example, a direction of −90° is the same as 270° measured counterclockwise from the positive x-axis.
Can I calculate distance if the axes use different units?
Convert both axes to a common length unit first. For example, change centimeters to meters before combining a horizontal change in meters with a vertical change in centimeters.
Can a distance and one endpoint identify the other point?
A positive distance gives a circle of possible endpoints centered on the known point. A second condition, such as the other point’s x-coordinate, narrows the possibilities.
Why is the origin sometimes outside the graph?
The graph zooms around the two endpoints so a short segment remains visible even when both points are far from the origin. Each axis uses the same scale, so the segment keeps its shape.
