距离与中点计算器
结果
距离与中点计算器 中使用的公式
In-Depth Tutorial: 距离与中点计算器
The Distance and Midpoint Calculator solves the two most-used formulas of coordinate geometry simultaneously from a single pair of points. Enter (x₁, y₁) and (x₂, y₂) and the calculator returns the distance between them (length of the segment) and the midpoint (the exact center of the segment). This tutorial derives both formulas from the Pythagorean theorem, walks through worked examples with negative and fractional coordinates, and shows how the same ideas extend to 3D.
Where the distance formula comes from
The distance formula is a direct application of the Pythagorean theorem. Given two points P₁ = (x₁, y₁) and P₂ = (x₂, y₂), draw a right triangle whose legs are parallel to the axes:
- Horizontal leg length: |x₂ − x₁|
- Vertical leg length: |y₂ − y₁|
- Hypotenuse: the distance d between P₁ and P₂
Pythagorean theorem says d² = (x₂ − x₁)² + (y₂ − y₁)². Taking the positive square root:
d = √((x₂ − x₁)² + (y₂ − y₁)²)
The absolute values disappear because squaring eliminates the sign. (x₂ − x₁)² is the same as (x₁ − x₂)² — so the order of the points does not matter; distance is always positive and symmetric.
Where the midpoint formula comes from
The midpoint is the average of the two endpoints, taken component-by-component:
M = ((x₁ + x₂)/2, (y₁ + y₂)/2)
Why averaging works: the midpoint is the point that is equidistant from both endpoints AND lies on the segment connecting them. The line from P₁ to P₂ is parametrized as P(t) = P₁ + t(P₂ − P₁) for t ∈ [0, 1]. At t = 0 you are at P₁, at t = 1 you are at P₂, and at t = 0.5 you are exactly in the middle: M = P₁ + 0.5(P₂ − P₁) = 0.5(P₁ + P₂), which is the average.
The midpoint formula does NOT have a square root — it is the linear midpoint, not derived from Pythagorean.
Example 1 — Two points in the first quadrant
Input: P₁ = (1, 2), P₂ = (4, 6).
- Δx = 4 − 1 = 3, Δy = 6 − 2 = 4
- Distance: d = √(3² + 4²) = √(9 + 16) = √25 = 5
- Midpoint: M = ((1+4)/2, (2+6)/2) = (2.5, 4)
Notice the 3-4-5 right triangle hiding inside: this is one of those Pythagorean triples that appears constantly in math problems.
Example 2 — Negative coordinates
Input: P₁ = (−2, −3), P₂ = (5, 1).
- Δx = 5 − (−2) = 7, Δy = 1 − (−3) = 4
- Distance: d = √(7² + 4²) = √(49 + 16) = √65 ≈ 8.062
- Midpoint: M = ((−2+5)/2, (−3+1)/2) = (1.5, −1)
Negative coordinates work fine — both formulas handle them naturally because of the squaring (distance) and averaging (midpoint). A common error is forgetting that subtracting a negative number flips its sign: 5 − (−2) = 5 + 2 = 7.
Example 3 — Fractional coordinates
Input: P₁ = (0.5, 1.5), P₂ = (2.5, 4.0).
- Δx = 2.0, Δy = 2.5
- Distance: d = √(4.0 + 6.25) = √10.25 ≈ 3.202
- Midpoint: M = (1.5, 2.75)
Three dimensions
Both formulas extend to 3D by adding a z-coordinate term:
- 3D distance: d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²)
- 3D midpoint: M = ((x₁+x₂)/2, (y₁+y₂)/2, (z₁+z₂)/2)
The 3D distance is still just the Pythagorean theorem, applied twice: once on the xy-plane to get the floor-projected distance, then again with that result and the z-difference. See the 3D Pythagorean Theorem Calculator for the explicit derivation.
Related formulas you may want
The distance and midpoint sit at the center of a small family of coordinate geometry formulas. Closely related:
- Slope (gradient): m = (y₂ − y₁)/(x₂ − x₁) — the rate of change between the two points, equal to rise/run.
- Point-slope form of a line: y − y₁ = m(x − x₁) — equation of the line through P₁ with slope m.
- Distance from a point to a line: |Ax + By + C| / √(A² + B²) for line Ax + By + C = 0.
- Section formula: the point dividing segment P₁P₂ in the ratio m:n is ((mx₂ + nx₁)/(m + n), (my₂ + ny₁)/(m + n)). The midpoint is the special case m = n = 1.
Real-world applications
- Navigation and mapping: GPS coordinates use latitude/longitude (not Cartesian), but for small distances on a flat-Earth approximation the same formula applies. For continent-scale distances you need spherical geometry (haversine formula).
- Physics: any "distance moved" calculation in 2D or 3D motion uses the distance formula. Velocity magnitude from velocity components: |v| = √(vx² + vy²) — same shape, vector components instead of coordinates.
- Computer graphics: every collision detection, every "is the mouse over this object" check, every shortest-path query — distance formula.
- Surveying and construction: laying out building corners, fencing diagonals, anything where you need to confirm two points are at a known distance.
Common mistakes
- Subtracting in the wrong order without squaring. The distance formula squares the differences, so direction does not matter. But if you forget to square (or take absolute value), you can get a negative distance — which is impossible.
- Confusing distance and midpoint formulas. Distance has a square root; midpoint is just an average. Mixing them gives a coordinate point where you want a number, or vice versa.
- Wrong parenthesization on negatives. (−2 − 4)² should be (−6)² = 36, not −36. Square the result, not the operation.
- Forgetting the 1/2 in the midpoint formula. The midpoint of (0, 0) and (4, 6) is (2, 3), not (4, 6). Divide each sum by 2.
常见问题解答 – 距离与中点计算器
距离:d = √((x₂−x₁)² + (y₂−y₁)²)。中点:M = ((x₁+x₂)/2, (y₁+y₂)/2)。两者都从两个坐标点同时计算。
中点是线段的精确中心——它距两个端点的距离相等。
是的——负坐标正常工作。公式对差值取平方,因此符号不影响结果。
是的——免费且无限制。