<p><strong>编辑2019:</strong>由于这个答案,我编写了一个问答风格示例来回答类似的问题(包括这个示例):<a href="https://stackoverflow.com/questions/45618544/how-to-calculate-3d-distance-including-altitude-between-two-points-in-geodjang">How to calculate 3D distance (including altitude) between two points in GeoDjango</a>。</p>
<p><em>排序:</em></p>
<p>我们需要使用<a href="https://en.wikipedia.org/wiki/Haversine_formula" rel="nofollow noreferrer">Haversine formula</a>或<a href="https://en.wikipedia.org/wiki/Vincenty%27s_formulae" rel="nofollow noreferrer">Vicenty formula</a>计算两点之间的2D<a href="https://en.wikipedia.org/wiki/Great-circle_distance" rel="nofollow noreferrer">great-circle distance</a>,然后我们可以将其与两点之间的高度差(delta)结合起来计算它们之间的<a href="https://en.wikipedia.org/wiki/Euclidean_distance" rel="nofollow noreferrer">Euclidean distance</a>,如下所示:</p>
<pre><code>dist = sqrt(great_circle((lat_1, lon_1), (lat_2, lon_2)).m**2, (alt_1 - alt_2)**2)
</code></pre>
<p>该解决方案假设高度以米为单位,因此也将<code>great_circle</code>的结果转换为米。</p>
<hr/>
<p><s>通过将坐标从<a href="https://en.wikipedia.org/wiki/Polar_coordinate_system" rel="nofollow noreferrer">Polar (long, lat, alt)</a>转换为<a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system" rel="nofollow noreferrer">Cartesian (x, y, z)</a>:</s></p>
<ul>
<li>让:<br/>
<code>polar_point_1 = (long_1, lat_1, alt_1)</code><br/>
以及<br/>{<cd3>}</li>
<li><p>使用以下公式将每个点转换为笛卡尔等价点:</p>
<pre><code>x = alt * cos(lat) * sin(long)
y = alt * sin(lat)
z = alt * cos(lat) * cos(long)
</code></pre>
<p>你将分别有<code>p_1 = (x_1, y_1, z_1)</code>和<code>p_2 = (x_2, y_2, z_2)</code>点。</p></li>
<li><p>最后使用欧几里德公式:</p>
<pre><code>dist = sqrt((x_2-x_1)**2 + (y_2-y_1)**2 + (z_2-z_1)**2)
</code></pre>
<p/></li>
</ul>