(几何学:大圆距离)编写一个程序,提示用户输入地球表面两点经度和纬度的度数然后显示它们的大圆距离。

本文介绍了一个使用Python编写的程序,该程序通过输入两个点的经纬度(度数),利用math库中的函数将其转换为弧度,并计算这两个点之间的球面距离。程序首先提示用户输入两个点的纬度和经度,然后将这些坐标转换为弧度,接着利用球面余弦定理计算两点间的距离,最后输出结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

程序如下:
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 %5.2f km”%d)

程序运行结果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值