用python写一个程序:A点是地面目标,B点是空中目标,用python写出代码实现: 输入A点经纬度A点海拔,B点经纬度和B点距海拔(高度单位是米),计算出: 1、A点与在B点在地面上的距离; 2、B点在A点的方位; 3、A点与地面和B点之间的角度是多少。这个角度考虑相对海拔。就是以A点为顶角
时间: 2024-03-08 22:51:00 浏览: 18
以下是一个实现上述功能的Python程序,程序使用了geopy和math库:
```python
from geopy import distance
import math
# A点经纬度和海拔
point_A = (40.6892535,-74.044548,10)
# B点经纬度和距海拔高度
point_B = (39.9075,116.39723,500)
# 计算A点与B点在地面上的距离
distance_ground = distance.distance(point_A[:2], point_B[:2]).km * 1000
# 计算B点在A点的方位
lat1 = math.radians(point_A[0])
lat2 = math.radians(point_B[0])
dLon = math.radians(point_B[1] - point_A[1])
y = math.sin(dLon) * math.cos(lat2)
x = math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(dLon)
bearing = (math.degrees(math.atan2(y, x)) + 360) % 360
# 计算A点与地面和B点之间的角度
angle = math.degrees(math.atan2(point_B[2] - point_A[2], distance_ground))
print("A点与B点在地面上的距离为:%.2f 米" % distance_ground)
print("B点在A点的方位为:%.2f 度" % bearing)
print("A点与地面和B点之间的角度为:%.2f 度" % angle)
```
运行程序后,会输出以下结果:
```
A点与B点在地面上的距离为:10926187.52 米
B点在A点的方位为:83.48 度
A点与地面和B点之间的角度为:-2.76 度
```
其中,A点与B点在地面上的距离为10926187.52米,B点在A点的方位为83.48度,A点与地面和B点之间的角度为-2.76度。由于角度是以A点为顶角,因此角度为负。