Skip to content

Commit f4db124

Browse files
committed
Redefine transformation functions to use a and b only.
1 parent 4d5f523 commit f4db124

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

ahrs/common/frames.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from .constants import RAD2DEG
4545
from .constants import DEG2RAD
4646

47-
def geodetic2ecef(lat: float, lon: float, h: float, a: float = EARTH_EQUATOR_RADIUS, ecc: float = EARTH_FIRST_ECCENTRICITY) -> np.ndarray:
47+
def geodetic2ecef(lat: float, lon: float, h: float, a: float = EARTH_EQUATOR_RADIUS, b: float = EARTH_POLAR_RADIUS) -> np.ndarray:
4848
"""
4949
Transform geodetic coordinates to Rectangular (Cartesian) Coordinates in
5050
the Earth-Centered Earth-Fixed frame.
@@ -106,14 +106,15 @@ def geodetic2ecef(lat: float, lon: float, h: float, a: float = EARTH_EQUATOR_RAD
106106
raise ValueError(f"Longitude must be between -180 and 180 degrees. Got {lon}")
107107
lat *= DEG2RAD
108108
lon *= DEG2RAD
109-
N = a/np.sqrt(1 - ecc**2 *np.sin(lat)**2)
109+
ecc2 = (a**2 - b**2)/a**2
110+
N = a/np.sqrt(1 - ecc2 *np.sin(lat)**2)
110111
X = np.zeros(3)
111112
X[0] = (N+h)*np.cos(lat)*np.cos(lon)
112113
X[1] = (N+h)*np.cos(lat)*np.sin(lon)
113-
X[2] = (N*(1.0-ecc**2)+h)*np.sin(lat)
114+
X[2] = (N*(1.0-ecc2)+h)*np.sin(lat)
114115
return X
115116

116-
def geodetic2enu(lat: float, lon: float, h: float, lat0: float, lon0: float, h0: float, a: float = EARTH_EQUATOR_RADIUS, ecc: float = EARTH_FIRST_ECCENTRICITY) -> np.ndarray:
117+
def geodetic2enu(lat: float, lon: float, h: float, lat0: float, lon0: float, h0: float, a: float = EARTH_EQUATOR_RADIUS, b: float = EARTH_POLAR_RADIUS) -> np.ndarray:
117118
"""
118119
Transform geodetic coordinates to east-north-up (ENU) coordinates
119120
:cite:p:`noureldin2013`.
@@ -189,8 +190,8 @@ def geodetic2enu(lat: float, lon: float, h: float, lat0: float, lon0: float, h0:
189190
190191
The ENU coordinates are computed as follows:
191192
"""
192-
x1, y1, z1 = geodetic2ecef(lat, lon, h, a, ecc)
193-
x2, y2, z2 = geodetic2ecef(lat0, lon0, h0, a, ecc)
193+
x1, y1, z1 = geodetic2ecef(lat, lon, h, a, b)
194+
x2, y2, z2 = geodetic2ecef(lat0, lon0, h0, a, b)
194195
return ecef2enuv(x1, y1, z1, x2, y2, z2, lat0, lon0)
195196

196197
def ecef2geodetic(x: float, y: float, z: float, a: float = EARTH_EQUATOR_RADIUS, b: float = EARTH_POLAR_RADIUS) -> np.ndarray:
@@ -357,7 +358,7 @@ def eci2ecef(w: float, t: float = 0) -> np.ndarray:
357358
[-np.sin(w)*t, np.cos(w)*t, 0.0],
358359
[ 0.0, 0.0, 1.0]])
359360

360-
def ecef2enu(x: float, y: float, z: float, lat: float, lon: float, h: float, a: float = EARTH_EQUATOR_RADIUS, ecc: float = EARTH_FIRST_ECCENTRICITY) -> np.ndarray:
361+
def ecef2enu(x: float, y: float, z: float, lat: float, lon: float, h: float, a: float = EARTH_EQUATOR_RADIUS, b: float = EARTH_POLAR_RADIUS) -> np.ndarray:
361362
"""
362363
Transform geocentric XYZ coordinates in ECEF-frame to Local East-North-Up
363364
(ENU) cartesian coordinates :cite:p:`noureldin2013`.
@@ -399,7 +400,7 @@ def ecef2enu(x: float, y: float, z: float, lat: float, lon: float, h: float, a:
399400
>>> ecef2enu(x, y, z, lat, lon, h)
400401
array([186.27751933, 286.84222383, 939.69262095])
401402
"""
402-
ecef = geodetic2ecef(lat, lon, h, a, ecc)
403+
ecef = geodetic2ecef(lat, lon, h, a, b)
403404
x0, y0, z0 = ecef
404405
return ecef2enuv(x, y, z, x0, y0, z0, lat, lon)
405406

@@ -521,7 +522,7 @@ def enu2uvw(east: float, north: float, up: float, lat: float, lon: float, angle_
521522
v = np.sin(lon) * t + np.cos(lon) * east
522523
return np.array([u, v, w])
523524

524-
def enu2ecef(east: float, north: float, up: float, lat: float, lon: float, h: float, a: float = EARTH_EQUATOR_RADIUS, ecc: float = EARTH_FIRST_ECCENTRICITY) -> np.ndarray:
525+
def enu2ecef(east: float, north: float, up: float, lat: float, lon: float, h: float, a: float = EARTH_EQUATOR_RADIUS, b: float = EARTH_POLAR_RADIUS) -> np.ndarray:
525526
"""
526527
Transforms the local east-north-up (ENU) Cartesian coordinates specified by
527528
east, north, and up to the geocentric Earth-centered Earth-fixed (ECEF)
@@ -552,7 +553,7 @@ def enu2ecef(east: float, north: float, up: float, lat: float, lon: float, h: fl
552553
ecef : numpy.ndarray
553554
ECEF cartesian coordinates.
554555
"""
555-
ecef = geodetic2ecef(lat, lon, h, a, ecc)
556+
ecef = geodetic2ecef(lat, lon, h, a, b)
556557
## Rotating ENU to ECEF
557558
uvw = enu2uvw(east, north, up, lat, lon, 'deg')
558559
## Origin + offset from origin equals position in ECEF

0 commit comments

Comments
 (0)