← 线段计算器 /

线段长度计算器

通过两端点坐标计算线段长度。

[email protected], Geometry Calculator Developer & Online Math Educator 审核 最后更新于 April 24, 2026

线段长度计算器

线段长度计算器 中使用的公式

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

In-Depth Tutorial: 线段长度计算器

A line segment is the straight portion of a line between two endpoints. Its length is the straight-line distance between those endpoints — measured by the distance formula:

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

This Segment Length Calculator takes the two endpoint coordinates and returns the segment's length. The formula is a direct application of the Pythagorean theorem to the horizontal and vertical differences between the points. This tutorial explains the derivation, walks through examples, and shows how segment length relates to displacement, distance, and the broader concept of metric.

How the formula comes from Pythagoras

Given two points P₁ = (x₁, y₁) and P₂ = (x₂, y₂), draw a right triangle whose:

  • Horizontal leg has length |x₂ − x₁| (the difference in x-coordinates)
  • Vertical leg has length |y₂ − y₁| (the difference in y-coordinates)
  • Hypotenuse is the segment from P₁ to P₂

By the Pythagorean theorem: d² = (x₂ − x₁)² + (y₂ − y₁)². Taking the positive square root: d = √((x₂ − x₁)² + (y₂ − y₁)²).

The absolute value bars in the legs disappear when we square — squaring eliminates signs. So we can drop the absolute values in the formula.

Worked example 1 — first quadrant

Find the length of the segment from P₁ = (3, 1) to P₂ = (7, 4).

Δx = 7 − 3 = 4, Δy = 4 − 1 = 3.
d = √(4² + 3²) = √(16 + 9) = √25 = 5.

Notice this is the 3-4-5 right triangle hidden inside coordinate geometry.

Worked example 2 — negative coordinates

Find the length from P₁ = (−2, 1) to P₂ = (3, −4).

Δx = 3 − (−2) = 5, Δy = −4 − 1 = −5.
d = √(25 + 25) = √50 ≈ 7.07.

Subtracting a negative is the same as adding the positive — 3 − (−2) = 5, not 1. Same for Δy: −4 − 1 = −5, which squared is 25.

Worked example 3 — vertical segment

Find the length from P₁ = (5, 2) to P₂ = (5, 8).

Δx = 0, Δy = 6.
d = √(0 + 36) = 6.

For purely vertical (or horizontal) segments, one of the coordinate differences is 0, and the formula simplifies to just the absolute value of the other difference.

The 3D extension

For two 3D points P₁ = (x₁, y₁, z₁) and P₂ = (x₂, y₂, z₂):

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

The pattern extends: add the z-coordinate squared difference. In any number of dimensions, the formula has the same "sum of squared differences under a square root" form.

Distance vs displacement

Two related but distinct concepts:

  • Distance (segment length): always a positive number. The magnitude of the segment. d = √(Δx² + Δy²).
  • Displacement: a vector with both magnitude AND direction. Written as (Δx, Δy). Can be "negative" in either component.

This calculator computes the distance (length) — a scalar. To get the vector displacement, look at the signed differences (x₂ − x₁) and (y₂ − y₁) separately.

Properties of segment length

  • Non-negative: length is always ≥ 0. The only "0-length" segment is one where both endpoints are the same point.
  • Symmetric: length(P₁, P₂) = length(P₂, P₁). Direction does not matter.
  • Triangle inequality: for any three points P, Q, R, length(P, R) ≤ length(P, Q) + length(Q, R). Going "through" Q is never shorter than going directly P to R.

These three properties are the defining axioms of a "metric space" — a generalization of distance to abstract mathematical spaces.

Related calculations

Real-world applications

  • Navigation. Computing straight-line distance between two GPS positions (for small distances on a flat-Earth approximation; spherical geometry for global scale).
  • Physics — kinematics. Distance moved between two times = segment length between two position vectors.
  • Computer graphics. Distance between any two screen pixels uses this formula directly.
  • Robotics. Path planning algorithms use segment length to evaluate route lengths.
  • Animation. Interpolating between two keyframes at constant speed requires computing segment length to map time to position.

Distance in non-Euclidean spaces

The Euclidean distance formula assumes a flat (Euclidean) coordinate plane. Other geometries use different distance formulas:

  • Manhattan distance (taxicab): d = |Δx| + |Δy|. Distance along a grid (like Manhattan streets) rather than diagonal.
  • Spherical distance (Earth-scale): use the haversine formula, which accounts for the Earth's curvature.
  • Hyperbolic distance: used in special relativity and non-Euclidean geometries.

For everyday school and engineering work, the Euclidean formula is what you want.

Common mistakes

  • Forgetting to square. The formula squares the differences, not just absolutes them. Forgetting to square gives a wrong (linear) result.
  • Forgetting to square-root at the end. The Pythagorean form gives d², not d. Take √ at the end.
  • Negative under the root. The expression (x₂−x₁)² + (y₂−y₁)² is always ≥ 0 because it's a sum of squares. If you got a negative, you made an algebra error.
  • Mixing 2D and 3D formulas. 2D has 2 squared terms, 3D has 3. Using the wrong formula gives the wrong dimension answer.

常见问题解答 – 线段长度计算器

距离公式:d = √((x₂−x₁)² + (y₂−y₁)²),由勾股定理应用于水平和垂直差导出。

是的——该公式对两个差值分别平方,因此负坐标也能正确计算。支持任意象限中的点。

距离(线段长度)始终为正。位移是有方向的向量——可以为负。此计算器计算距离。

是的——免费且无限制。