2点間の距離を計算する

ヒュベニの距離計算式Python のコードに落としてみた.

import math
a2 = 6378137.0 ** 2
b2 = 6356752.314140 ** 2
e2 = (a2 - b2) / a2
def distance_by_hubeny(p1, p2):
    def d2r(deg):
        return deg * (2 * math.pi) / 360
    (lon1, lat1, lon2, lat2) = map(d2r, p1 + p2)
    w = 1 - e2 * math.sin((lat1 + lat2) / 2) ** 2
    c2 = math.cos((lat1 + lat2) / 2) ** 2
    return math.sqrt((b2 / w ** 3) * (lat1 - lat2) ** 2 + (a2 / w) * c2 * (lon1 - lon2) ** 2)

てすつ

>>> print distance_by_hubeny([139.76608157157898,35.68137872227962],  [135.49497485160828,34.70190356670296])
403982.095331

Google Maps は 403.53km だと言っているけど、0.11%のズレなら誤差だろうと思うことにする.