Length of a Line Segment Calculator

Enter the coordinates of two endpoints to get the segment's length, midpoint, slope, and angle of inclination using the distance formula.

Quick Facts

Distance formula
d = √((x2−x1)² + (y2−y1)²)
Derived from the Pythagorean theorem — the coordinate differences are the two legs of a right triangle.
Midpoint formula
M = ((x1+x2)/2, (y1+y2)/2)
The point exactly halfway between the two endpoints.
Slope formula
m = (y2−y1)/(x2−x1)
Undefined for a vertical segment (x1 = x2).

Your Results

Calculated
Segment Length
-
d = √((x2−x1)² + (y2−y1)²)
Midpoint
-
((x1+x2)/2, (y1+y2)/2)
Slope
-
(y2−y1)/(x2−x1)
Angle of Inclination
-
From the positive x-axis

Ready

Enter both endpoints and press Calculate.

Formula and Method for the Length of a Line Segment

A line segment is the straight path connecting two fixed points on a coordinate plane. If the endpoints are (x1, y1) and (x2, y2), the segment's length comes from the distance formula: d = √((x2 − x1)² + (y2 − y1)²). This calculator also derives the segment's midpoint, slope, and angle of inclination from the same two points.

How the calculation works

Enter the coordinates of both endpoints. The calculator finds the horizontal difference (x2 − x1) and vertical difference (y2 − y1), squares each, adds them together, and takes the square root — this is just the Pythagorean theorem, since the segment is the hypotenuse of a right triangle whose legs are those two differences. The midpoint averages the x-coordinates and y-coordinates separately: M = ((x1+x2)/2, (y1+y2)/2). The slope is the "rise over run," m = (y2−y1)/(x2−x1), and the angle of inclination is the angle that slope makes with the positive x-axis, computed as atan2(y2−y1, x2−x1) and normalized to 0°–360°.

Common mistakes

  • Subtracting in the wrong order inconsistently: for length the order does not matter (the differences are squared), but for slope and angle you must keep (x2−x1) and (y2−y1) paired from the same point order.
  • Confusing length with slope: length is a distance in coordinate units; slope is a unitless ratio describing steepness — they answer different questions.
  • Forgetting the vertical-line case: when x1 = x2, the run is zero, so the slope is undefined (not zero) and the segment is vertical with a 90° angle of inclination.

Real-world applications

  • Geometry and trigonometry problems use the distance formula to find side lengths of triangles and polygons plotted on a coordinate grid.
  • Navigation, mapping, and CAD software use the same formula to compute straight-line distances between two plotted coordinates.
  • Physics uses the distance formula to find displacement magnitude between two position points.
  • Construction and surveying layouts use the midpoint and slope to check that a line runs true and to mark its exact center point.

Frequently Asked Questions

What is the formula for the length of a line segment?
Given two endpoints (x1, y1) and (x2, y2), the length is d = √((x2 − x1)² + (y2 − y1)²). This comes directly from the Pythagorean theorem, treating the horizontal difference (x2 − x1) and vertical difference (y2 − y1) as the legs of a right triangle and the segment itself as the hypotenuse.
How do you find the midpoint of a line segment?
Average the x-coordinates and the y-coordinates separately: M = ((x1 + x2) / 2, (y1 + y2) / 2). The midpoint always lies exactly halfway along the segment.
What happens when the line segment is vertical or horizontal?
If x1 = x2, the segment is vertical and its slope is undefined (division by zero); the angle of inclination is 90°. If y1 = y2, the segment is horizontal, the slope is 0, and the angle is 0°. The distance formula still works normally in both cases.
Does the order of the two points change the length?
No. Because both differences are squared before being added, d = √((x2 − x1)² + (y2 − y1)²) gives the same result regardless of which point is labeled (x1, y1) and which is (x2, y2).