geomath.py 文件源码

python
阅读 43 收藏 0 点赞 0 评论 0

项目:AboveTustin 作者: kevinabrandon 项目源码 文件源码
def distance(pointA, pointB):
    """
    Calculate the great circle distance between two points 
    on the earth (specified in decimal degrees)

    http://stackoverflow.com/questions/15736995/how-can-i-quickly-estimate-the-distance-between-two-latitude-longitude-points
    """
    # convert decimal degrees to radians 
    lon1, lat1, lon2, lat2 = map(math.radians, [pointA[1], pointA[0], pointB[1], pointB[0]])

    # haversine formula 
    dlon = lon2 - lon1 
    dlat = lat2 - lat1 
    a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
    c = 2 * math.asin(math.sqrt(a)) 
    r = 3956  # Radius of earth in miles. Use 6371 for kilometers
    return c * r
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号