Midpoint & Distance Calculator
Calculate the midpoint, distance, and slope between two points in 2D or 3D. Shows formulas with substituted values and an SVG coordinate plot for 2D.
This calculator finds the midpoint, Euclidean distance, and slope between two points in 2D or 3D coordinate space. Enter any pair of coordinates and the tool shows each formula with your actual values substituted step by step, along with an SVG coordinate plot for 2D inputs that marks both points, the midpoint, and the connecting line segment.
About Midpoint & Distance Calculator
How the Distance Formula Works
The distance formula is a direct application of the Pythagorean theorem to coordinate geometry. Given two points A(x₁, y₁) and B(x₂, y₂), the horizontal separation is Δx = x₂ - x₁ and the vertical separation is Δy = y₂ - y₁. These form the two legs of a right triangle, and the distance between the points is the hypotenuse:
d = √((x₂ - x₁)² + (y₂ - y₁)²)
The Pythagorean theorem itself dates back to at least 1900-1600 BCE, with Babylonian tablets showing knowledge of the relationship and lists of Pythagorean triples. Euclid formally proved it around 300 BCE as Proposition 47 of Book I of his Elements, according to Proclus. The step from geometry to coordinate-based distance came much later. Rene Descartes introduced Cartesian coordinates in 1637, creating the link between algebra and geometry. The distance formula as an algebraic expression was first published by Alexis Clairaut in 1731, building on Descartes' coordinate system.
In three dimensions, the formula extends naturally by adding a z-component:
d = √((x₂ - x₁)² + (y₂ - y₁)² + (z₂ - z₁)²)
The Three Core Formulas
| Formula | 2D | 3D |
|---|---|---|
| Distance | d = √((x₂-x₁)² + (y₂-y₁)²) | d = √((x₂-x₁)² + (y₂-y₁)² + (z₂-z₁)²) |
| Midpoint | M = ((x₁+x₂)/2, (y₁+y₂)/2) | M = ((x₁+x₂)/2, (y₁+y₂)/2, (z₁+z₂)/2) |
| Slope | m = (y₂-y₁) / (x₂-x₁) | Not applicable (single slope) |
All three formulas use the same coordinate differences (Δx and Δy) but combine them differently. Distance squares and sums them (Pythagorean theorem), slope divides them (rise over run), and midpoint averages the raw coordinates.
Worked Example: 2D Distance
Find the distance between A(2, 3) and B(8, 11):
- Δx = 8 - 2 = 6
- Δy = 11 - 3 = 8
- d = √(6² + 8²) = √(36 + 64) = √100 = 10 units
This is a classic 3-4-5 Pythagorean triple scaled by 2 (giving 6-8-10). The line from (2, 3) to (8, 11) is the hypotenuse of a right triangle with legs 6 and 8. Recognising Pythagorean triples like 3-4-5, 5-12-13, and 8-15-17 can speed up distance calculations without a calculator.
Worked Example: Midpoint
Find the midpoint of A(2, 3) and B(8, 11):
- Mx = (2 + 8) / 2 = 5
- My = (3 + 11) / 2 = 7
- M = (5, 7)
The midpoint is the average of each coordinate pair independently. It always lies exactly halfway along the line segment. This extends to 3D by simply averaging the z-coordinates as well: Mz = (z₁ + z₂) / 2.
Worked Example: Slope
Find the slope between A(2, 3) and B(8, 11):
- m = (11 - 3) / (8 - 2) = 8 / 6 = 4/3 (about 1.333)
A slope of 4/3 means for every 3 units of horizontal movement, the line rises 4 units vertically. The angle of inclination is arctan(4/3), roughly 53.1 degrees from horizontal. For a deeper look at slope with line equations in slope-intercept and point-slope forms, see the slope calculator.
Special Slope Cases
| Slope Value | Meaning | Angle | Example Points |
|---|---|---|---|
| m = 0 | Horizontal line | 0 degrees | (1, 5) and (7, 5) |
| 0 < m < 1 | Gentle rise | 0-45 degrees | (0, 0) and (4, 2) |
| m = 1 | 45 degree angle | 45 degrees | (0, 0) and (5, 5) |
| m > 1 | Steep rise | 45-90 degrees | (0, 0) and (2, 6) |
| m < 0 | Falling left to right | Negative angle | (0, 4) and (3, 0) |
| Undefined | Vertical line (Δx = 0) | 90 degrees | (3, 1) and (3, 8) |
3D Distance Example
Find the distance between A(1, 2, 3) and B(4, 6, 8):
- Δx = 4 - 1 = 3, Δy = 6 - 2 = 4, Δz = 8 - 3 = 5
- d = √(3² + 4² + 5²) = √(9 + 16 + 25) = √50 = 5√2, roughly 7.071 units
This is another example involving a Pythagorean triple at its core: the 2D distance from the Δx and Δy components alone would be √(9 + 16) = 5, and then the full 3D distance adds the Δz component. The 3D midpoint would be ((1+4)/2, (2+6)/2, (3+8)/2) = (2.5, 4, 5.5).
Where Are These Formulas Used in Practice?
The distance and midpoint formulas show up in many fields beyond the classroom.
Game development and collision detection. In 2D and 3D games, collision detection between circular or spherical objects works by calculating the Euclidean distance between their centres and comparing it to the sum of their radii. If the distance is less than or equal to the combined radii, a collision has occurred. As a performance optimisation, game engines often compare the squared distance against the squared sum of radii, avoiding the relatively expensive square root operation. Mozilla's MDN Web Docs documents this technique as the standard approach for both 2D circle-based and 3D sphere-based collision detection.
Machine learning and data science. The k-nearest neighbours (KNN) algorithm, one of the most widely used classification methods, relies on Euclidean distance as its default distance metric. KNN classifies a data point by finding the k closest training examples measured by distance and assigning the majority class. K-means clustering also uses squared Euclidean distance to assign data points to clusters and update centroids. The scikit-learn documentation notes that Euclidean distance works well in low-to-moderate dimensions but becomes less discriminating in very high-dimensional spaces, where all points tend toward equal distance from one another.
Surveying and construction. Surveyors use midpoints as reference points when dividing land parcels and establishing boundary markers. Highway engineers apply midpoint calculations to find optimal placement for rest stops and emergency exits between two landmarks. In construction, finding the midpoint of a wall helps with centering fixtures, and the distance formula verifies measurements between reference points. The Pythagorean theorem calculator covers the underlying geometry that makes these measurements work.
Navigation and mapping. GPS systems use a spherical version of the distance formula (the haversine formula) for long distances over the Earth's curved surface. For short distances within a city or a building, the flat Euclidean approximation is accurate enough and much simpler to compute.
Common Pythagorean Triples Reference
These integer-valued right triangle side lengths produce clean distance calculations without irrational square roots. Recognising them saves time on exams and in practice.
| Triple (a, b, c) | Common Scaled Versions | Distance for (0,0) to (a,b) |
|---|---|---|
| 3, 4, 5 | 6-8-10, 9-12-15, 12-16-20 | 5 |
| 5, 12, 13 | 10-24-26, 15-36-39 | 13 |
| 8, 15, 17 | 16-30-34 | 17 |
| 7, 24, 25 | 14-48-50 | 25 |
| 20, 21, 29 | 40-42-58 | 29 |
Any multiple of a Pythagorean triple is also a Pythagorean triple. For example, if the distance between two points involves Δx = 12 and Δy = 16, that is 4 times the 3-4-5 triple, so the distance is 4 x 5 = 20 without needing a calculator.
Euclidean vs Manhattan vs Chebyshev Distance
The Euclidean distance calculated here is the most common distance metric, but it is not the only one. In a city with a grid layout, you cannot walk diagonally through buildings - you must follow the streets. That grid-following distance is called Manhattan distance (or taxicab distance), calculated as |Δx| + |Δy|. For two points with Δx = 3 and Δy = 4, the Euclidean distance is 5 (diagonal shortcut) while the Manhattan distance is 7 (walking the grid). A third option is Chebyshev distance, which equals the larger of |Δx| and |Δy| - this models movement on a chessboard where a king can move diagonally. For Δx = 3 and Δy = 4, the Chebyshev distance is 4. Each metric suits different contexts: Euclidean for straight-line measurement, Manhattan for grid-based routing, and Chebyshev for chessboard-style problems.
Common Mistakes to Avoid
- Forgetting to square before adding. The formula requires (Δx)² + (Δy)², not Δx + Δy. Adding the raw differences gives the Manhattan distance, which is a different metric altogether.
- Squaring the entire sum. Calculate (x₂ - x₁)² and (y₂ - y₁)² separately, then add. Do not compute (x₂ - x₁ + y₂ - y₁)².
- Swapping the order inconsistently. It does not matter if you use (x₂ - x₁) or (x₁ - x₂) since squaring removes the sign. But be consistent across Δx and Δy to avoid confusion, especially when calculating slope where the sign matters.
- Mixing up distance and displacement. Distance is always a positive scalar. Displacement is a vector with direction. The distance formula gives magnitude only.
- Using the midpoint formula for weighted averages. The midpoint formula assumes equal weighting. If one point has more weight (for example, in a centre-of-mass problem), use the weighted average formula instead.
For visualising these relationships on a full coordinate plane with function plotting, the graphing calculator lets you plot points and lines interactively.
Sources
Frequently Asked Questions
How do you calculate the distance between two points?
For 2D, use the distance formula: d = square root of ((x2-x1) squared + (y2-y1) squared). For 3D, add the z term: d = square root of ((x2-x1) squared + (y2-y1) squared + (z2-z1) squared). Both are based on the Pythagorean theorem.
How do you find the midpoint?
Average the coordinates: midpoint = ((x1+x2)/2, (y1+y2)/2) for 2D, or add (z1+z2)/2 for 3D. The midpoint is the exact centre of the line segment connecting the two points.
What is the relationship between distance and slope?
Slope measures steepness (rise over run) while distance measures total length. They use the same deltas (x2-x1 and y2-y1) but combine them differently. Slope is dy/dx while distance is the square root of dx squared plus dy squared.
Can the distance between two points be negative?
No. Distance is always zero or positive because you are squaring the differences before taking the square root. A distance of zero means the two points are the same.
Does the 3D midpoint formula work the same way?
Yes. In 3D, you simply average each coordinate independently: ((x1+x2)/2, (y1+y2)/2, (z1+z2)/2). The distance formula also extends naturally by adding the z-component.
Related Tools
Link to this tool
Copy this HTML to link to this tool from your website or blog.
<a href="https://toolboxkit.io/tools/midpoint-distance-calculator/" title="Midpoint & Distance Calculator - Free Online Tool">Try Midpoint & Distance Calculator on ToolboxKit.io</a>