Distance and Midpoint Calculator
Enter two points. The calculator gives the straight-line distance between them, the midpoint, the slope and angle of the line joining them, and the point a chosen ratio of the way along.
Distance
5 ft
Midpoint
(2.5, 4)
Slope (2D)
1.3333
Angle from the x axis (2D)
53.13°
Point dividing the segment m:n
(2.5, 4)
How it works
The distance between two points is the hypotenuse of a right triangle whose legs are the difference in x and the difference in y (and, in 3D, the difference in z): the Pythagorean theorem gives √(Δx² + Δy² + Δz²). The midpoint is simply the average of the two points, coordinate by coordinate.
The slope of the segment is rise over run, Δy ÷ Δx, and the angle is the direction of the segment measured counter-clockwise from the positive x axis. A vertical segment has no slope (division by zero) and an angle of 90°; both are defined only in two dimensions.
The section formula generalises the midpoint: the point that divides the segment in the ratio m : n, counting m parts from the first point and n parts from the second, is the weighted average (n·P₁ + m·P₂) ÷ (m + n). With m = n it is the midpoint; with m = 1, n = 2 it is one third of the way from the first point.
Formula
distance = √((x₂ − x₁)² + (y₂ − y₁)² [+ (z₂ − z₁)²]) midpoint = ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2 [, (z₁ + z₂) ÷ 2]) slope = (y₂ − y₁) ÷ (x₂ − x₁) angle = atan2(y₂ − y₁, x₂ − x₁) m:n point = ((n·x₁ + m·x₂) ÷ (m + n), (n·y₁ + m·y₂) ÷ (m + n) [, …])
Example
From (1, 2) to (4, 6): Δx = 3 and Δy = 4, so the distance is √(9 + 16) = 5 ft. The midpoint is ((1 + 4) ÷ 2, (2 + 6) ÷ 2) = (2.5, 4). The slope is 4 ÷ 3 = 1.3333 and the angle is atan(4 ÷ 3) = 53.13°. With the ratio 1 : 2 the dividing point is ((2 × 1 + 1 × 4) ÷ 3, (2 × 2 + 1 × 6) ÷ 3) = (2, 3.3333).
In 3D, from (1, 2, 3) to (4, 6, 15): Δ = (3, 4, 12), so the distance is √(9 + 16 + 144) = √169 = 13 and the midpoint is (2.5, 4, 9).
Assumptions and limitations
- Coordinates are Cartesian, on a flat plane or in ordinary space. For latitude and longitude use a great-circle distance instead.
- All coordinates share one unit, the one you choose, and the distance is in that unit. The unit is a label; nothing is converted.
- The m : n point is an internal division: both parts are positive and the point lies between the two ends.
- The angle is measured counter-clockwise from the positive x axis, between −180° and 180°.
Frequently asked questions
Why does the slope show a dash?
The segment is vertical (x₁ = x₂), so rise over run divides by zero and the slope is undefined; the angle still reads 90° or −90°. In 3D a single slope does not describe a direction, so it is not reported there either.
More in Math & Geometry calculators.