(几何学:大圆距离)大网里离是球面上两点之间的跑商。假设(x1,川)和(22,12)是两点的
经度和纬度,两点之问的大网距高可以用下面的公式计算:
d = radins * arccos(sin(x,) * sin(*2) + cos(r.) x cos(r;) * cos(V, - 13))
编写一个程序,提示用户输人地球表面两点经度和纬度的度数然后品示它们的大网距离。
球的半均半径为 6371.01km。注意:你需要使用math.radians 两数将度数转换成孤度数,因为
Python 三角两数使用的都是孤度。公式中的经纬度是西经和北纬。用负数表示东经和南纬。下面
-个示例运行。
Enter point 1 (latitude and longitude) in degrees:
39.55, -116.25 l-Enter
Enter point 2 (latitude and longitude) in degrees:
41.5, 87.37 -Enter
The distance between the two points is 10691.79183231593 km
import math
x1,y1 = eval(input("Please input point1(latitude and longitude) in degrees:"))
x2,y2 = eval(input("Please input point2(latitude and longitude) in degrees:"))
radius = 6371.01
x11 = math.radians(x1) #math.radians()函数将度数转换成弧度数
y11 = math.radians(y1)
x22 = math.radians(x2)
y22 = math.radians(y2)
d = radius * math.acos(math.sin(x11) * math.sin(x22) + math.cos(x11) * math.cos(x22) * math.cos(y11-y22))
print("The distance between the two points is %f km"%d)