Distance Calculator - 2D and 3D Coordinate Distance
Enter two coordinate points to find the exact Euclidean distance between them. Choose 2D mode (x, y) for plane geometry or 3D mode (x, y, z) for space geometry. Results update as you type and include the midpoint, slope (in 2D), the full step-by-step working, and a live shape diagram showing the segment on a coordinate grid.
Formula
Worked example
Find the distance between A(1, 2) and B(5, 6): delta-x = 5 - 1 = 4, delta-y = 6 - 2 = 4. Then d = sqrt(4^2 + 4^2) = sqrt(16 + 16) = sqrt(32) = 4*sqrt(2) approximately 5.6569 units. Midpoint = ((1+5)/2, (2+6)/2) = (3, 4). Slope = 4/4 = 1.
What is the distance formula?
The distance between two points is the length of the straight line segment connecting them. In a 2D coordinate plane, this is derived directly from the Pythagorean theorem. If the two points are A(x1, y1) and B(x2, y2), draw a right triangle with the segment AB as its hypotenuse. The horizontal leg has length |x2 - x1| and the vertical leg has length |y2 - y1|. By Pythagoras, d^2 = (x2 - x1)^2 + (y2 - y1)^2, so d = sqrt((x2 - x1)^2 + (y2 - y1)^2). In 3D, a third term (z2 - z1)^2 is added under the radical, extending the same idea into space.
Midpoint and slope from the same two points
Once you have two points, two related quantities are immediately useful. The midpoint is the point exactly halfway along the segment: M = ((x1 + x2) / 2, (y1 + y2) / 2). It is the average of each pair of coordinates. The slope of the line through the points is the rise over the run: m = (y2 - y1) / (x2 - x1). Slope is undefined when x1 = x2 because the line is perfectly vertical. With the slope and either original point you can write the full equation of the line using the point-slope form y - y1 = m(x - x1).
How to use this calculator
Select 2D or 3D mode, then enter the coordinates of your two points. Every output updates instantly: the Euclidean distance, the squared distance, the midpoint coordinates, the individual deltas (delta-x, delta-y, delta-z), and the slope (2D only). The step-by-step panel shows every arithmetic stage so you can follow the working or use it as a classroom check. The bar chart at the top lets you see the signed horizontal and vertical displacements at a glance.
Applications of the distance formula
The Euclidean distance formula appears across science, engineering and computing. In physics it gives the magnitude of a displacement vector. In machine learning it is the core of k-nearest-neighbour classification and k-means clustering. In computer graphics it underlies collision detection and lighting calculations. In navigation, the 3D version finds range between two aircraft or submarines. In statistics, generalised distance in n-dimensional space (Mahalanobis distance) extends the same idea to account for correlations between variables.
Distance formula reference
| Dimensions | Formula | Variables |
|---|---|---|
| 1D | d = |x2 - x1| | x1, x2 |
| 2D (plane) | d = sqrt((x2-x1)^2 + (y2-y1)^2) | x1, y1, x2, y2 |
| 3D (space) | d = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2) | x1, y1, z1, x2, y2, z2 |
| nD (general) | d = sqrt(sum of (ai-bi)^2 for i=1..n) | all coordinate pairs |
The Euclidean distance formula extended from 1D to 4D. The same pattern applies to any number of dimensions.
Frequently asked questions
What is the distance between two points formula?
In two dimensions the formula is d = sqrt((x2 - x1)^2 + (y2 - y1)^2). It comes directly from the Pythagorean theorem applied to the right triangle whose hypotenuse is the segment between the two points. In three dimensions a third squared difference is added: d = sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2).
How do I find the midpoint of a segment?
Average each pair of corresponding coordinates. In 2D, midpoint M = ((x1 + x2) / 2, (y1 + y2) / 2). In 3D, also average the z-coordinates: M = ((x1 + x2) / 2, (y1 + y2) / 2, (z1 + z2) / 2). This gives the point exactly halfway between A and B.
Can the distance between two points ever be negative?
No. Distance is a non-negative scalar quantity. It is zero only when the two points are identical, and positive for any two distinct points. The formula always takes the square root of a sum of squares, which is never negative.
What is the difference between 2D and 3D distance?
In 2D you only have x and y coordinates, so the formula uses two squared differences. In 3D you also have a z-coordinate, so a third squared difference (z2 - z1)^2 is added under the square root. The idea is identical - it is still the straight-line length of the segment in the relevant number of dimensions.
What does distance squared tell me?
Distance squared (d^2 = (x2-x1)^2 + (y2-y1)^2) is the sum of squared differences before taking the square root. It is used in many algorithms to avoid the cost of a square root operation when you only need to compare distances (the smaller d^2 is always the smaller d). It is also the squared length of the displacement vector between the two points.
How is slope related to the distance formula?
Slope m = (y2 - y1) / (x2 - x1) uses the same delta-x and delta-y differences as the distance formula. While distance combines them as the hypotenuse of the right triangle, slope is just the ratio of the vertical leg to the horizontal leg - the tangent of the angle the segment makes with the horizontal axis.