小さな自律RCカープロジェクトの一環として、haversine distanceとangle calculatorをPythonで書いています。私の2つの試験場所は38.63594444444444,-90.2315
と38.63594444444444,-90.23211111111111
です。なぜ私のPython haversine距離計算は、オンラインツールやGoogleマップに比べて間違っていますか?
ほとんどのオンライン電卓(および私の個人的なTI-89)の距離は約0.05308kmです。しかし、私のPython関数は0.06795 kmの距離を得ています。それは〜15メートルオフであり、それは小さなRCカーで巨大です。
私の軸受け計算機能points2angle
は、toDegrees
機能で浮動鋳造を行うまで失敗していました。整数部が私を苦しめていた。
私のpoints2angle
とpoints2distance
関数は(度、分、秒)のタプルが必要であることに注意してください。 2つのテスト場所は、その形式の(38, 38, 9.4), (-90, 13, 53.4)
と(38, 38, 9.4), (-90, 13, 55.6)
です。
編集:ありがとうございますMSeifert。私はちょうど私の緯度と経度が混ざった。私はpoints2angle
コードを以下のように修正しましたが、私のpoints2distance
コードにエラーを残しました。私の間違ったコードとその答えの違いはまだ明らかです。
マイ距離計算(間違った距離が返さ):
def points2distance(start, end):
start_long = math.radians(toDegrees(start[0]))
start_latt = math.radians(toDegrees(start[1]))
end_long = math.radians(toDegrees(end[0]))
end_latt = math.radians(toDegrees(end[1]))
d_latt = float(end_latt - start_latt)
d_long = float(end_long - start_long)
a = (math.sin(d_latt/2)**2) + math.cos(start_latt) * math.cos(end_latt)* (math.sin(d_long/2)**2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
return 6371 * c
マイ小数度変換機能(作動):
def toDegrees(coord):
degrees = float(math.fabs(coord[0])) + float(coord[1]/60) + float(coord[2]/3600)
if coord[0] < 0:
degrees = degrees*-1
return degrees
マイ方位角計算(作業):
def points2angle(start, end):
start_long = math.radians(toDegrees(start[1]))
start_latt = math.radians(toDegrees(start[0]))
end_long = math.radians(toDegrees(end[1]))
end_latt = math.radians(toDegrees(end[0]))
d_latt = end_latt - start_latt
d_long = end_long - start_long
y = math.sin(d_long)*math.sin(end_latt)
x = (math.cos(start_latt)*math.sin(end_latt)) - (math.sin(start_latt)*math.cos(end_latt)*math.cos(d_long))
brng = math.degrees(math.atan2(y,x))
compBear = (brng+360) % 360;
return compBear
完璧な答え。しかし、私は今、ポイントミス計算を壊してしまった。なぜなら、私はそのミックスアップがどこにでもあることを確かめたいからだ。私はそれを修正すると更新されます。ありがとうございました! **更新:**私の質問では 'points2angle'の計算が修正されました。 – Hellcat707
それですべてが動いているのですか、それともまだ矛盾していますか?私はこれまであなたを助けることができてうれしいです。 :) – MSeifert
ええ、すべてが動作していると私は本当にそれを感謝します。時にはそれは余分な目を必要とします!最初の投稿で新しく動作するコードに 'points2angle'コードを更新したことを確認しました。私は間違いなくそのコードのすべての変数を切り替えました。しかし、今はすべて修正されています。私はあなたのポストに投票することができますが、私は十分な担当者がありません。 – Hellcat707