-
Notifications
You must be signed in to change notification settings - Fork 2
/
xyz2ell3.py
35 lines (32 loc) · 1.29 KB
/
xyz2ell3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import math
def xyz2ell3(X,Y,Z,a,b,e2):
#% XYZ2ELL3 Converts cartesian coordinates to ellipsoidal.
#% Uses direct algorithm in B.R. Bowring, "The accuracy of
#% geodetic latitude and height equations", Survey
#% Review, v28 #218, October 1985, pp.202-206. Vectorized.
#% See also XYZ2ELL, XYZ2ELL2.
#% Version: 2011-02-19
#% Useage: [lat,lon,h]=xyz2ell3(X,Y,Z,a,b,e2)
#% [lat,lon,h]=xyz2ell3(X,Y,Z)
#% Input: X \
#% Y > vectors of cartesian coordinates in CT system (m)
#% Z /
#% a - ref. ellipsoid major semi-axis (m) default GRS80
#% b - ref. ellipsoid minor semi-axis (m) default GRS80
#% e2 - ref. ellipsoid eccentricity squared default GRS80
#% Output: lat - vector of ellipsoidal latitudes (radians)
#% lon - vector of ellipsoidal longitudes (radians)
#% h - vector of ellipsoidal heights (m)
#
#% Copyright (c) 2011, Michael R. Craymer
#% All rights reserved.
#% Email: [email protected]
lon = math.atan2(Y,X)
e = e2*(a/b)^2
p = math.sqrt(X*X+Y*Y)
r = math.sqrt(p*p+Z*Z)
u = math.atan(b*Z*(1+e*b/r)/(a*p))
lat = math.atan((Z+e*b*math.sin(u)^3)/(p-e2*a*math.cos(u)^3))
v = a/math.sqrt(1-e2*math.sin(lat)^2)
h = p*math.cos(lat)+Z*math.sin(lat)-a*a/v
return (lat,lon,h)