matlab 方位角 经纬度,经纬度转方位角,用python实现
时间: 2023-08-26 07:20:44 浏览: 95
基于python实现地址和经纬度转换
5星 · 资源好评率100%
以下是经纬度转方位角的 Python 实现示例:
```python
import math
def ll2az(lat1, lon1, lat2, lon2):
# 将经纬度转化为弧度
lat1 = math.radians(lat1)
lon1 = math.radians(lon1)
lat2 = math.radians(lat2)
lon2 = math.radians(lon2)
# 计算方位角和仰角
delta_lon = lon2 - lon1
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)
azimuth = math.atan2(y, x)
elevation = math.atan2(math.sin(lat2 - lat1), math.cos(lat1) * math.cos(lat2) * math.cos(delta_lon))
# 将弧度转化为度数
azimuth = math.degrees(azimuth)
elevation = math.degrees(elevation)
return azimuth, elevation
```
示例用法:
```python
lat1 = 30.5225
lon1 = 114.3586
lat2 = 30.5178
lon2 = 114.3553
azimuth, elevation = ll2az(lat1, lon1, lat2, lon2)
print('起点(%f, %f),终点(%f, %f)的方位角为%f度,仰角为%f度。' % (lat1, lon1, lat2, lon2, azimuth, elevation))
```
阅读全文