Py学习  »  Python

用Python中纬度计算地球半径-复制公式

Kah • 4 年前 • 226 次点击  

我试图复制我在这个网站上找到的一个公式,它涉及到计算给定纬度的地球半径。

https://rechneronline.de/earth-radius/ https://planetcalc.com/7721/

然后我使用网站上的计算器来确定我是否正确地复制了公式。

我已经写了下面的代码,但是我不能复制网站上给出的答案(除非纬度等于零)。因为方程很复杂,我甚至把每个部分分成了一个单独的变量。但是,我的结果仍然不正确。

示例代码

import math

def radius (B):
  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

例如,使用纬度2(变量B),网站计算地球半径为6378.111km我的答案是6360.481公里。

任何帮助都将不胜感激。提前谢谢你

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/49291
 
226 次点击  
文章 [ 2 ]  |  最新文章 4 年前
foxpal
Reply   •   1 楼
foxpal    4 年前

那是因为 math.cos math.sin 以弧度表示。您需要将函数顶部的度数转换为弧度:

B *= math.pi/180
nikhildr22
Reply   •   2 楼
nikhildr22    4 年前

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