短い答え
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.
重要なポイント
- ユークリッド距離は常に 2 点間の可能な最短経路です。斜めに切ることができないため、マンハッタンの距離は常に等しいかそれ以上になります。
- Euclidean and Manhattan distance are only equal when the two points share an x or y coordinate — movement along a single axis.
- ミンコフスキー距離は一般化です。p = 1 はマンハッタンを与え、p = 2 はユークリッドを与え、p = ∞ はチェビシェフ距離 (最大の単一軸の差) を与えます。
- 地球の表面は湾曲しているため、座標間の地理的距離には平面距離の公式ではなく、ハバーサインの公式が必要です。
適切な距離公式の選択
| シナリオ | 式 | なぜ |
|---|---|---|
| 平面上の直線距離 | ユークリッド | 可能な最短のパス |
| 街区/グリッドに沿った距離 | マンハッタン | ブロックを斜めに切ることはできない |
| 2 つの地球座標間の距離 | 地理的 (ハーバーシン) | 惑星の曲率を考慮する |
| 一般的な調整可能な距離メトリック | ミンコフスキー | ユークリッド、マンハッタン、チェビシェフをカバーするファミリー |
Worked example: three distances, one pair of points
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ᵢ|ᵖ)^(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 未満のミンコフスキー パラメーター p を使用し、通常の距離の動作が期待されます。p = 1 未満では、式は三角不等式を満たさず、真の距離計量のように動作しなくなります。
- 負の座標が負の距離を生成するのではないかと心配します。二乗法 (ユークリッド) と絶対値 (マンハッタン) は両方とも符号を削除するため、距離が負になることはなく、点の順序は重要ではありません。
関連する電卓
- ピタゴラスの定理電卓 — see the right-triangle logic behind the 2D Euclidean distance formula.
- 直角三角形計算機 — 2 つの点によって形成される三角形の辺と角度を解きます。
- 傾斜計算機 — 2 つの点を結ぶ線の急勾配を見つけます。
- 三角形の計算機 — 3 点と一般的な三角形ジオメトリを操作します。