私信  •  关注

nikhildr22

nikhildr22 最近创建的主题
nikhildr22 最近回复了
4 年前
回复了 nikhildr22 创建的主题 » 用Python中纬度计算地球半径-复制公式

python数学库将弧度作为三角函数的输入,

所以一定要把B的值转换成弧度

它可以通过 B=math.radians(B)

最终代码:

import math
def radius (B):
    B=math.radians(B) #converting into radians
    a = 6378.137  #Radius at sea level at equator
    b = 6356.752  #Radius at poles
    c = (a**2*math.cos(B))**2
    d = (b**2*math.sin(B))**2
    e = (a*math.cos(B))**2
    f = (b*math.sin(B))**2
    R = math.sqrt((c+d)/(e+f))
    return R