简短的回答
The right distance formula depends on how you're allowed to travel between two points. Straight-line ("as the crow flies") distance uses the Euclidean formula, d = √[(x₂−x₁)² + (y₂−y₁)²]. Grid-based movement, like city blocks, uses Manhattan distance instead: d = |x₂−x₁| + |y₂−y₁|. For places on Earth, geographic distance accounts for the planet's curvature using the Haversine formula.
要点
- 欧氏距离始终是两点之间可能的最短路径;曼哈顿距离总是等于或更长,因为它不能对角切割。
- 仅当两点共享 x 或 y 坐标(沿单个轴移动)时,欧几里得距离和曼哈顿距离才相等。
- 闵可夫斯基距离是一种概括:p = 1 给出曼哈顿距离,p = 2 给出欧几里德距离,p = ∞ 给出切比雪夫距离(最大单轴差)。
- 坐标之间的地理距离需要半正弦公式,而不是平面距离公式,因为地球表面是弯曲的。
选择正确的距离公式
| 设想 | 公式 | 为什么 |
|---|---|---|
| 平面上的直线距离 | 欧几里得 | 最短路径 |
| 沿城市街区/网格的距离 | 曼哈顿 | 无法对角切割方块 |
| 两个地球坐标之间的距离 | 地理(半正矢) | 考虑行星的曲率 |
| 一般可调距离度量 | 明科夫斯基 | 涵盖欧几里得、曼哈顿和切比雪夫的系列 |
工作示例:三个距离,一对点
Take the points (0, 0) and (3, 4). Depending on the metric, "the distance" between them isn't a single number:
| 公制 | 计算 | 结果 |
|---|---|---|
| 欧几里得 (p=2) | √(3² + 4²) = √25 | 5 |
| 曼哈顿 (p=1) | |3| + |4| | 7 |
| 切比雪夫 (p=∞) | max(3, 4) | 4 |
All three answers are correct — for their own definition of "distance." Euclidean gives the shortest path (a straight line), Manhattan gives the longest (grid-only movement), and Chebyshev gives the shortest of all, since it only counts the larger of the two axis differences.
闵可夫斯基距离家庭
d = (Σ|x − y|v)^(1/p)
Minkowski distance is a single formula with a tunable parameter p. Setting p = 1 reduces it to Manhattan distance, p = 2 reduces it to Euclidean distance, and as p approaches infinity, it converges to Chebyshev distance — the largest single-axis gap between the two points. This makes Minkowski distance a useful way to sweep between "grid movement" and "straight-line movement" behavior for the same pair of points.
要避免的常见错误
- 使用欧几里得距离来估计城市网格中的实际行驶距离 - 它低估了实际的步行或驾驶距离,而曼哈顿距离的模型更真实。
- 将平面距离公式直接应用于纬度/经度坐标 - 根据纬度,经度覆盖的现实世界距离非常不同,因此需要使用半正弦公式。
- 使用小于 1 的 Minkowski 参数 p 并期望正常距离行为(低于 p = 1),该公式不再满足三角不等式并且不再表现得像真正的距离度量。
- 担心负坐标会产生负距离 - 平方(欧几里得)和绝对值(曼哈顿)都删除符号,因此距离永远不会是负数,点顺序也无关紧要。
相关计算器
- 毕达哥拉斯定理计算器 — 请参阅二维欧几里得距离公式背后的直角三角形逻辑。
- 直角三角形计算器 — 求解由两点形成的三角形的边和角。
- 坡度计算器 — 找出连接两点的直线的陡度。
- 三角形计算器 — 处理三点和一般三角形几何。