spherical distance

spherical distance

请添加图片描述

import math


def spherical_distance(lat1, lon1, lat2, lon2):
    """
    Calculates the great circle distance given
    the latitudes and longitudes of two points.
    Input
     lat1, lon1: lat and long in degrees for the first point
     lat2, lon2: lat and long in degrees for the second point
    Output
     d: great circle distance
    """
    D = 3959   # earth radius in miles
    phi1 = math.radians(lat1)
    lambda1 = math.radians(lon1)
    phi2 = math.radians(lat2)
    lambda2 = math.radians(lon2)
    dlambda = lambda2 - lambda1

    dphi = phi2 - phi1
    sinlat = math.sin(dphi/2.0)
    sinlong = math.sin(dlambda/2.0)

    alpha = (sinlat*sinlat) + math.cos(phi1) * \
        math.cos(phi2) * (sinlong*sinlong)
    c = 2 * math.asin(min(1, math.sqrt(alpha)))
    d = D*c
    return d


if __name__ == "__main__":
    # Columbus, OH lat2, lon2 = 39.91, 116.56 # Beijing print spdist(lat1, lon1, lat2, lon2)
    lat1, lon1 = 40, -83
    lat2, lon2 = 39.91, 116.56
    print(spherical_distance(lat1, lon1, lat2, lon2))
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值