用python写一段三点坐标计算密位角的代码
时间: 2023-05-11 21:07:40 浏览: 153
以下是用 Python 编写的计算密位角的代码:
```python
import math
def calculate_bearing(lat1, lon1, lat2, lon2):
"""
Calculate the bearing between two points on Earth.
"""
# Convert latitude and longitude to radians
lat1 = math.radians(lat1)
lon1 = math.radians(lon1)
lat2 = math.radians(lat2)
lon2 = math.radians(lon2)
# Calculate the difference between the longitudes
delta_lon = lon2 - lon1
# Calculate the bearing
y = math.sin(delta_lon) * math.cos(lat2)
x = math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(delta_lon)
bearing = math.atan2(y, x)
# Convert bearing to degrees
bearing = math.degrees(bearing)
# Normalize bearing to range 0-360
bearing = (bearing + 360) % 360
return bearing
```
这个函数接受四个参数:起点纬度、起点经度、终点纬度和终点经度。它返回两个点之间的方位角,以度为单位。
阅读全文