/ /どのようにPythonを使用して2つの球の点のユークリッド距離と大きな円距離を比較するには? - python、numpy、ユークリッド距離、大きな円

どのようにPythonを使用して2つの球の点のユークリッド距離と大きな円の距離を比較するには? - python、numpy、ユークリッド距離、大きな円

私は導入されたエラーをチェックしようとしています大円距離(gcd)ではなく、地球上の2点の距離をユークリッド距離で計算すると、私はその緯度と経度で定義される2つの点を持っています。 私はpython geopyフレームワークを 大円距離。 gcdのコードは次のとおりです。

def measure(self, a, b):
a, b = Point(a), Point(b)

lat1, lng1 = radians(degrees=a.latitude), radians(degrees=a.longitude)
lat2, lng2 = radians(degrees=b.latitude), radians(degrees=b.longitude)

sin_lat1, cos_lat1 = sin(lat1), cos(lat1)
sin_lat2, cos_lat2 = sin(lat2), cos(lat2)

delta_lng = lng2 - lng1
cos_delta_lng, sin_delta_lng = cos(delta_lng), sin(delta_lng)

d = atan2(sqrt((cos_lat2 * sin_delta_lng) ** 2 +
(cos_lat1 * sin_lat2 -
sin_lat1 * cos_lat2 * cos_delta_lng) ** 2),
sin_lat1 * sin_lat2 + cos_lat1 * cos_lat2 * cos_delta_lng)

return self.RADIUS * d

だから2つのポイント:

p1 = [39.8616、-75.0748]、p2 = [ - 7.30933,112.76]

その

gcd = 78.8433004543197 klm

を使用して great_circle(p1,p2).kilometers ジオピーからの関数

私はこの数式を使ってデカルト座標系でこれら2つの点を変換しました:

  def spherical_to_cartesian(r,la,lo):
x=r*np.sin(90-la)*np.cos(lo)
y=r*np.sin(90-la)*np.sin(lo)
z=r*np.cos(90-la)
return (x,y,z)

どこで r=6372.795これは、次のデカルト座標系の座標になります

p1=[ -765.81579368,  -256.69640558,  6321.40405587],
p2=[480.8302149,-168.64726394,-6352.39140142]

次に、次のように入力します。 np.linalg.norm(p2-p1) 私は得る 1103.4963114787836 彼らのユークリッドの規範として、gcdから〜78klmと比較して妥当でないように見える。

回答:

回答№1は1

Pythonには、数学パッケージに2つの関数が含まれています。ラジアンは度をラジアンに変換し、度はラジアンを度に変換します。

sin()メソッドはxの正弦をラジアンで返します。

import math
def spherical_to_cartesian(r,la,lo):
rlo = math.radians(lo)
rla = math.radians(90-la)
x=r*np.sin(rla)*np.cos(rlo)
y=r*np.sin(rla)*np.sin(rlo)
z=r*np.cos(rla)
return (x,y,z)