Length Of A Line Segment Calculator - Distance, Midpoint, Slope
Use this length of a line segment calculator to find the distance between two endpoints in 2D or 3D, plus the midpoint and slope of the segment.
Length Of A Line Segment Calculator
Results
What Is the Length of a Line Segment?
The length of a line segment is the straight-line distance between its two endpoints, which makes it the most fundamental measurement you can take on a segment in analytic geometry.
- • Coordinate geometry homework: Verify the distance between two plotted points, including the 3-4-5 and 5-12-13 right triangles that show up constantly in textbooks.
- • CAD, mapping, and design layouts: Quickly check the linear distance between two reference points in 2D drawings or full 3D models before cutting or placing parts.
- • Physics and engineering problems: Compute displacement between an initial position and a final position when the path is a single straight segment.
- • Game development and computer graphics: Measure the distance between two game objects, vertices in a 3D mesh, or waypoints in a navigation graph.
A line segment is the portion of a line bounded by two distinct endpoints, so it always has a finite, non-negative length equal to the Euclidean distance between them. Leave the z values at 0 for a 2D problem, or enter nonzero z1 and z2 for a 3D segment, and the result updates as you type.
When the segment is the chord of a circle, Chord Length Calculator applies the same distance formula between two points on the circumference.
How the Length of a Line Segment Is Calculated
The calculator applies the Euclidean distance formula to the two endpoints you enter. For a 2D segment between (x1, y1) and (x2, y2), the length is the square root of the sum of squared coordinate differences; a 3D segment adds a third squared term for the z difference.
- x1, y1, z1: Coordinates of the first endpoint. Use the same unit system throughout (meters, feet, centimeters, or unitless coordinates).
- x2, y2, z2: Coordinates of the second endpoint. Leave z1 and z2 at 0 for a 2D problem so the third term drops out.
- L: Length of the line segment, returned in the same unit system as the coordinates.
Squaring the differences removes any sign, so negative coordinates work the same as positive ones, and the square root of a non-negative sum is always non-negative.
Worked example: a 3-4-5 right triangle
Endpoints: (0, 0) and (3, 4), z1 = z2 = 0 (2D case). dx = 3, dy = 4, dz = 0. L = sqrt(9 + 16) = 5.
xy-plane slope = dy / dx = 4 / 3 ≈ 1.3333.
Length of the line segment = 5 units, slope (xy-plane) ≈ 1.3333.
The segment is the hypotenuse of the classic 3-4-5 right triangle, confirming the distance from the origin to (3, 4) is exactly 5.
Worked example: a 3D diagonal of a unit cube
Endpoints: (0, 0, 0) and (1, 1, 1). dx = 1, dy = 1, dz = 1. L = sqrt(3) ≈ 1.7320508.
xy-plane slope = dy / dx = 1. The z difference contributes to the length but not the slope row.
Length of the line segment ≈ 1.7320508 units, slope (xy-plane) = 1.
The space diagonal of a unit cube has length sqrt(3) and updates as you type.
According to Wolfram MathWorld, the Euclidean distance between two points is d = sqrt((x2 - x1)^2 + (y2 - y1)^2) in 2D and extends to 3D as d = sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2).
According to Wikipedia, the Euclidean distance between two points in the plane equals the length of the line segment connecting them and is computed from the square root of the sum of squared coordinate differences.
To check the integer legs of a right triangle, Pythagorean Triples Calculator lists every classic triple, including 3-4-5 and 5-12-13, that the length of a line segment formula evaluates to exactly.
Key Concepts Explained
Four small ideas show up every time you measure a line segment. Understanding them keeps the calculator output honest.
Endpoint coordinates
The two endpoints are the only inputs that matter. Every result is derived from these four (2D) or six (3D) numbers.
Coordinate differences (dx, dy, dz)
The length depends only on the differences between matching coordinates, not on where the segment sits on the plane. Translating both endpoints by the same amount does not change the length of the line segment.
Midpoint as the geometric center
The midpoint is the point exactly halfway between the two endpoints. It is the average of the matching coordinates and is used heavily in geometry, statistics, and physics to summarize a segment.
Slope (xy-plane) and vertical segments
Slope is rise over run projected onto the xy-plane, dy / dx. When the endpoints share the same x, the segment is vertical, the xy-plane slope is undefined, and the length equals the absolute y difference. In 3D the z separation still contributes to the length but not the displayed slope.
These four concepts map directly onto the calculator outputs, so each one shows up as a labeled row in the results panel.
When the segment is one side of a right triangle, Right Triangle Calculator fills in the remaining sides, angles, and area from the same two-endpoint input style.
How to Use This Calculator
Using the calculator is a four-step flow. Open the page, type the endpoint coordinates, and read the results on the right.
- 1 Enter the first endpoint: Type the x and y (and z, for 3D) coordinates of the first endpoint. The defaults (0, 0, 0) are a useful starting point for an origin-based segment.
- 2 Enter the second endpoint: Type the x and y (and z, for 3D) coordinates of the second endpoint. The defaults (5, 12, 0) form a 5-12-13 right triangle so you can confirm the formula immediately.
- 3 Read the length of the line segment: The Euclidean distance appears at the top of the results panel and updates as you type. The page reports 4 decimal places for sub-unit accuracy and 2 for larger values.
- 4 Check the midpoint and slope: The midpoint triple and the xy-plane slope appear below the length. Use the slope to classify the segment as horizontal (0), vertical (undefined), or sloped.
- 5 Switch to 3D if needed: Type nonzero z1 and z2 to extend the formula to 3D. The length grows by the square root of the squared z difference, the midpoint triple now includes a z value, and the slope row keeps the xy-plane projection.
- 6 Reset and try another segment: Press Reset to restore the default endpoints, which is the fastest way to compare several line segments side by side.
Suppose you are measuring a wall that runs from (0, 0) to (3, 4) on a floor plan measured in meters. Type 0 and 0 for the first endpoint, then 3 and 4 for the second. The length of the line segment reads 5 m, the midpoint is (1.5, 2), and the slope of the wall is 4/3.
Benefits of Using This Calculator
These benefits come from real measurement, drafting, and study tasks rather than treating the tool as a generic math toy.
- • Two endpoints in, full geometry out: Returns length, midpoint, and slope at once, so one form fill replaces three separate computations.
- • Works in 2D and 3D without switching tools: Leave z1 and z2 at 0 for a 2D problem, then enter nonzero z values for a 3D segment. The same formula generalizes through the z-axis term.
- • Catches vertical segments explicitly: The xy-plane slope row reports 'undefined' for vertical segments instead of producing a divide-by-zero error, so the length and midpoint still display correctly.
- • Slope stays interpretable in 3D: For 3D segments the xy-plane slope is still useful for the projected view, while the full 3D direction comes from the (dx, dy, dz) triple.
- • Real-time updates as you type: Every change to an endpoint refreshes the results in real time, which is useful for sensitivity checks.
- • Accepts negative coordinates: Origin-crossing or negative coordinates work the same as positive ones because the squared differences remove any sign, keeping textbook problems and CAD coordinates on equal footing.
- • Pairs with related geometry tools: The same math powers the chord length, arc length, slope, and Pythagorean solvers here, so you can switch tools without re-entering values.
The biggest practical benefit is that the length of a line segment becomes a single reading instead of a multi-step calculation, and the value can be copied straight into a worksheet or fixture specification.
When the length of a line segment is one side of a triangle, Triangle Calculator fills in the remaining sides, angles, and area from the same coordinate inputs.
Factors That Affect Your Results
These factors determine whether the calculator's result matches the value you need on a drawing, in a model, or on paper.
Choice of coordinate system
The result is unitless beyond the unit system you choose. If your coordinates are in meters, the length is in meters; if they are in inches, the length is in inches. Mixing unit systems for x and y produces a meaningless number.
Number of dimensions
Adding a nonzero z1 - z2 difference increases the length of the line segment by sqrt(dz^2). For a horizontal 2D segment the z values contribute nothing, while a 3D diagonal of a unit cube grows from 1 to sqrt(3).
Numerical precision of the inputs
The calculator reports 4 decimal places for typical values and 2 for very large ones. Higher input precision generally yields higher output precision, but rounding the inputs first will round the result.
Vertical or horizontal segments
Vertical segments have an undefined xy-plane slope and a length equal to the absolute y difference; horizontal segments have a slope of 0 and a length equal to the absolute x difference. In 3D the z separation adds to the length without affecting the slope row.
Identical endpoints
When both endpoints coincide, the length is 0 and the midpoint equals that point. This is the degenerate case and the only situation in which the length is exactly zero.
- • The calculator assumes a flat Euclidean plane or space. On a curved surface such as a sphere, the length of a line segment must be computed along a great circle and will not match the Euclidean value.
- • The result reflects the straight-line distance between the endpoints, not the path length along a curve. For piecewise or curved paths, integrate or sum the segment lengths individually.
Treat the length of a line segment as an exact analytic value whenever the endpoints are coordinates in a flat space. For geographic, geodetic, or curved-surface problems, use a distance-on-sphere tool instead, since the chord on a sphere is always shorter than the surface arc.
According to Wikipedia, a line segment is the part of a line bounded by two distinct endpoints, so it always has a finite, non-negative length that can be measured directly between those two endpoints.
If the endpoint coordinates need to be in a different unit system or reference frame, Coordinates Converter translates the numbers before the segment length is computed.
Frequently Asked Questions
Q: What is the formula for the length of a line segment?
A: In 2D, the length of a line segment between (x1, y1) and (x2, y2) is L = sqrt((x2 - x1)^2 + (y2 - y1)^2). In 3D the formula adds a third squared term for the z difference, becoming L = sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2).
Q: How do you find the length of a line segment with two endpoints?
A: Subtract the matching coordinates of the endpoints to get dx, dy, and (for 3D) dz. Square each difference, sum the squares, and take the square root. The result is the length of the line segment in the same unit system as the coordinates.
Q: How do you find the length of a line segment in 3D?
A: Use L = sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2). The added z term accounts for the vertical separation between the endpoints and reduces to the 2D formula when both z values are 0.
Q: What is the difference between a line and a line segment?
A: A line extends infinitely in both directions, while a line segment is bounded by two distinct endpoints. A line segment therefore has a finite, non-negative length that can be measured directly, whereas a line has no length at all.
Q: Can the length of a line segment be negative?
A: No. Length is a non-negative scalar. Squared differences are non-negative, the sum is non-negative, and the square root of a non-negative number is non-negative, so the result is always 0 or positive regardless of the signs of the input coordinates.
Q: How are midpoint and length of a line segment related?
A: The midpoint sits exactly halfway between the two endpoints as the average of their coordinates, while the length is the distance from either endpoint to the midpoint multiplied by 2. Knowing one of them fixes the other once the endpoints are given.