Line: Distance / Midpoint / Slope
Given two points, get distance, midpoint, slope and line equation.
Overview
The Line Geometry tool takes two points in the plane and reports their distance, midpoint, slope and the equation of the line through them in slope-intercept form. Enter two (x, y) pairs and you get every basic property you might need for an analytic-geometry problem.
It is built for students working through coordinate geometry, GIS analysts measuring straight-line distances between markers and game developers checking projectile paths. Each value falls out of a one-line formula but they're easy to mix up under time pressure.
How it works
For points P1 = (x1, y1) and P2 = (x2, y2):
- Distance:
d = sqrt((x2 - x1)^2 + (y2 - y1)^2)(Pythagoras). - Midpoint:
((x1 + x2) / 2, (y1 + y2) / 2). - Slope:
m = (y2 - y1) / (x2 - x1), undefined when the line is vertical. - Equation:
y = m * x + bwhereb = y1 - m * x1. For vertical lines, the form isx = x1.
Examples
P1 = (0, 0), P2 = (3, 4)
→ distance 5, midpoint (1.5, 2), slope 4/3
→ equation y = (4/3)x
P1 = (1, 2), P2 = (5, 10)
→ distance ≈ 8.944, midpoint (3, 6), slope 2
→ equation y = 2x
P1 = (2, 3), P2 = (2, 9)
→ vertical line, equation x = 2
P1 = (-1, 4), P2 = (3, -4)
→ slope -2, equation y = -2x + 2
FAQ
What if the two points are the same?
Distance is zero, slope is undefined and no unique line passes through a single point.
Why is the slope undefined for vertical lines?
The denominator x2 - x1 is zero. The line still exists but in the form x = constant, which has no slope-intercept representation.
Does the order of the two points matter?
For distance and midpoint, no. For slope, swapping the points gives the same value because both differences flip sign.
Can I get the perpendicular line?
Yes — once you have slope m, the perpendicular passing through the midpoint has slope -1 / m. Build the equation with the new slope and the same intercept formula.
Is the distance formula tied to the Pythagorean theorem?
It's a direct application. The horizontal and vertical legs are x2 - x1 and y2 - y1, and the hypotenuse is the distance.