码迷,mamicode.com
首页 > 其他好文 > 详细

大地坐标系和空间直角坐标系的转换

时间:2020-03-15 16:21:57      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:转换   坐标   gre   transform   空间   pow   return   python   int   

大地坐标系转空间直角坐标系

import math
A_ALIS = 6378137
B_ALIS = 6356752.3142

E = math.sqrt(A_ALIS * A_ALIS - B_ALIS * B_ALIS) / A_ALIS

def transform_latlonhei2xyz(lon, lat, h):
    """ 大地坐标系 转 空间直角坐标系 """
    lon, lat, h = math.radians(float(lon)), math.radians(float(lat)), float(h)

    W = math.sqrt(1 - E * E * math.sin(lat) * math.sin(lat))
    N = A_ALIS / W

    x = (N + h) * math.cos(lat) * math.cos(lon)
    y = (N + h) * math.cos(lat) * math.sin(lon)
    z = (N * (1 - E * E) + h) * math.sin(lat)

    return x, y, z

print(transform_dadi2zhijiao(lon=121.4533008922, lat=31.1720088176, h=15.069))
# (-2850172.518796192, 4659579.331978275, 3282233.397176004)

  空间直角坐标系转大地坐标系

import math
A_ALIS = 6378137
B_ALIS = 6356752.3142
E2 = (A_ALIS * A_ALIS - B_ALIS * B_ALIS) / (B_ALIS * B_ALIS)
def transform_xyz2latlonhei(x, y, z):
    """空间直角坐标系转大地坐标系 """
lon = math.degrees(math.atan2(y, x))

S = math.atan2(z * A_ALIS, math.sqrt(x * x + y * y) * B_ALIS)

lat = math.atan2(z + E2 * B_ALIS * math.pow(math.sin(S), 3),
(math.sqrt(x * x + y * y) - E * E * A_ALIS * math.pow(math.cos(S), 3)))

W = math.sqrt(1 - E * E * math.sin(lat) * math.sin(lat))
N = A_ALIS / W
hei = math.sqrt(x * x + y * y) / math.cos(lat) - N

lat = math.degrees(lat)
return lon, lat, hei
print(transform_zhijiao2dadi(x=-2850172.518796192, y=4659579.331978275, z=3282233.397176004)) 
#(121.4533008922, 31.1720088176, 15.06900000013411)

  

大地坐标系和空间直角坐标系的转换

标签:转换   坐标   gre   transform   空间   pow   return   python   int   

原文地址:https://www.cnblogs.com/dasheng-maritime/p/12498146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!