Logo

MonoCalc

/

Line Length Calculator

Geometry

Coordinate Mode

Point A

X₁

Y₁

Point B

X₂

Y₂

AB

Line Length (d)

5

(3-4-5 triple)

Δx

3

Δy

4

Slope

1.333333

Angle

53.1301°

Midpoint

(2.5, 4)

Unit Vector

(0.6, 0.8)

About This Tool

Line Length Calculator – Measure Segment Length in 2D and 3D

A line length (or line segment length) is the straight-line distance between two defined endpoints. This calculator applies the Euclidean distance formula derived from the Pythagorean theorem to compute that distance precisely, and also returns the slope, angle of inclination, midpoint, and unit vector of the segment — all from a single pair of coordinate inputs.

The Euclidean Distance Formula

Given two points A = (x₁, y₁) and B = (x₂, y₂) in a flat coordinate plane, the length of segment AB is:

d = √((x₂ − x₁)² + (y₂ − y₁)²)

This formula follows directly from the Pythagorean theorem. The horizontal separation Δx and vertical separation Δy form the two legs of a right triangle, and the segment itself is the hypotenuse. Squaring, summing, and taking the square root yields the exact length.

Extending to 3D Space

For points in three-dimensional space, a third coordinate Z is added. The 3D formula is:

d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

Toggle the calculator to 3D mode to reveal Z-coordinate fields. This is useful for spatial geometry, CAD design, 3D game development, and physics problems involving three-dimensional displacement vectors.

Additional Outputs Explained

Beyond the primary line length, the calculator also displays:

  • Δx and Δy (and Δz in 3D) — the signed component differences (x₂ − x₁), (y₂ − y₁), and (z₂ − z₁). These are the projections of the segment onto each axis.
  • Slope — defined as m = Δy / Δx in 2D. A positive slope rises left to right; a negative slope falls. When Δx = 0 (vertical segment), slope is mathematically undefined and the calculator displays "Undefined".
  • Angle — the angle the segment makes with the positive x-axis, in degrees. Computed as θ = arctan2(Δy, Δx) × (180 / π). Values range from −180° to 180°.
  • Midpoint — the point exactly halfway between A and B:M = ((x₁ + x₂) / 2, (y₁ + y₂) / 2).
  • Unit vector — the segment direction normalized to length 1:û = (Δx / d, Δy / d). Unit vectors encode pure direction without magnitude and are widely used in physics, computer graphics, and game development.

Pythagorean Triple Detection

When the three values |Δx|, |Δy|, and d are all whole numbers, the calculator checks whether they match a Pythagorean triple — a set of integers (a, b, c) satisfying a² + b² = c². The classic example is (3, 4, 5): a segment from (0, 0) to (3, 4) has a length of exactly 5. Other well-known triples include 5-12-13, 8-15-17, and 7-24-25. Recognizing these triples is useful in geometry proofs, construction, and puzzle design.

Common Applications

Education and geometry — verifying side lengths in coordinate geometry problems, proving triangle properties, and computing perimeters of polygons whose vertices are given as coordinate pairs.

Engineering and CAD — measuring distances between component endpoints on technical drawings, checking tolerance compliance, and computing cable or pipe runs between two known positions.

Game and app development — computing the distance between two game objects for collision detection, pathfinding heuristics, and rendering decisions. The unit vector output is especially useful for normalizing movement direction.

Physics — finding displacement magnitude from initial and final position coordinates, and computing the direction of the displacement vector using the angle or unit vector outputs.

Horizontal and Vertical Segments

Axis-aligned segments have a simplified length calculation. For a horizontal segment (y₁ = y₂), the length reduces to |x₂ − x₁|. For a vertical segment (x₁ = x₂), the length reduces to |y₂ − y₁|. The calculator detects these cases automatically and labels the result accordingly.

Precision and Limitations

All calculations use JavaScript's 64-bit IEEE 754 floating-point arithmetic, which provides roughly 15–16 significant decimal digits — sufficient for almost all practical applications. The Pythagorean triple detector uses a small tolerance (10⁻⁹) to handle floating-point rounding and correctly identifies near-integer results as exact. The tool operates in abstract coordinate units — if your coordinates are in meters, the output is in meters; no unit conversion is applied.

Frequently Asked Questions

Is the Line Length Calculator free?

Yes, Line Length Calculator is totally free :)

Can I use the Line Length Calculator offline?

Yes, you can install the webapp as PWA.

Is it safe to use Line Length Calculator?

Yes, any data related to Line Length Calculator only stored in your browser (if storage required). You can simply clear browser cache to clear all the stored data. We do not store any data on server.

What formula does the Line Length Calculator use?

In 2D mode the calculator applies the Euclidean distance formula: d = √((x₂ − x₁)² + (y₂ − y₁)²). In 3D mode it extends to three dimensions: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²). Both formulas are direct applications of the Pythagorean theorem.

Can I calculate line length in 3D space?

Yes. Toggle the mode switch to 3D and enter Z-coordinates for both points. The calculator automatically adds a third term (z₂ − z₁)² under the square root, giving the straight-line distance through three-dimensional space.

What happens if both points are the same?

When both endpoints share the same coordinates, the line length is 0. The tool displays 0 as a valid result — no error is shown. The unit vector is undefined in this degenerate case and is displayed as 'N/A'.

What does the unit vector in the results represent?

The unit vector is the direction vector of the segment scaled to length 1: û = (Δx / d, Δy / d). It shows the orientation of the line without encoding its magnitude. Unit vectors are useful in physics for representing direction of motion, forces, and in graphics for normalizing displacement.

How is the slope displayed when the segment is vertical?

When x₁ = x₂ (both points share the same X coordinate), the slope m = Δy / Δx involves division by zero and is mathematically undefined. The calculator displays 'Undefined' in this case and shows the angle as 90° or −90° depending on the direction of the segment.

Can I use negative or decimal coordinate values?

Yes. The calculator accepts any real number — positive, negative, and decimal values are all valid. For example, points (−3.5, 2) and (4.5, −6) are handled correctly. There are no magnitude constraints on coordinates.