@@ -29,13 +29,13 @@ def lla2ecef(lat, lng, h):
29
29
ECEF coordinates in meters
30
30
"""
31
31
if abs (lat ) > 90 :
32
- raise ValueError (' latitude should be -90º <= latitude <= 90º' )
32
+ raise ValueError (" latitude should be -90º <= latitude <= 90º" )
33
33
34
34
if abs (lng ) > 180 :
35
- raise ValueError (' longitude should be -180º <= longitude <= 180º' )
35
+ raise ValueError (" longitude should be -180º <= longitude <= 180º" )
36
36
37
37
if not (0 <= h <= 84852.05 ):
38
- msg = ' pressure model is only valid if 0 <= h <= 84852.05'
38
+ msg = " pressure model is only valid if 0 <= h <= 84852.05"
39
39
raise ValueError (msg )
40
40
41
41
a = 6378137 # [m] Earth equatorial axis
@@ -45,11 +45,11 @@ def lla2ecef(lat, lng, h):
45
45
lat = deg2rad (lat ) # degrees to radians
46
46
lng = deg2rad (lng ) # degrees to radians
47
47
48
- N = a / (1 - (e * sin (lat ))** 2 ) ** ( .5 )
48
+ N = a / (1 - (e * sin (lat )) ** 2 ) ** ( 0 .5 )
49
49
50
50
x = (N + h ) * cos (lat ) * cos (lng )
51
51
y = (N + h ) * cos (lat ) * sin (lng )
52
- z = (((b / a ) ** 2 ) * N + h ) * sin (lat )
52
+ z = (((b / a ) ** 2 ) * N + h ) * sin (lat )
53
53
54
54
return array ([x , y , z ])
55
55
@@ -75,17 +75,21 @@ def ned2ecef(v_ned, lat, lng):
75
75
vector expressed in ECEF coordinates
76
76
"""
77
77
if abs (lat ) > 90 :
78
- raise ValueError (' latitude should be -90º <= latitude <= 90º' )
78
+ raise ValueError (" latitude should be -90º <= latitude <= 90º" )
79
79
80
80
if abs (lng ) > 180 :
81
- raise ValueError (' longitude should be -180º <= longitude <= 180º' )
81
+ raise ValueError (" longitude should be -180º <= longitude <= 180º" )
82
82
83
83
lat = deg2rad (lat )
84
84
lng = deg2rad (lng )
85
85
86
- Lne = array ([[- sin (lat ) * cos (lng ), - sin (lat ) * sin (lng ), cos (lat )],
87
- [- sin (lng ), cos (lng ), 0 ],
88
- [- cos (lat ) * cos (lng ), - cos (lat ) * sin (lng ), - sin (lat )]])
86
+ Lne = array (
87
+ [
88
+ [- sin (lat ) * cos (lng ), - sin (lat ) * sin (lng ), cos (lat )],
89
+ [- sin (lng ), cos (lng ), 0 ],
90
+ [- cos (lat ) * cos (lng ), - cos (lat ) * sin (lng ), - sin (lat )],
91
+ ]
92
+ )
89
93
90
94
Len = Lne .transpose ()
91
95
v_ecef = Len .dot (v_ned )
@@ -114,17 +118,21 @@ def ecef2ned(v_ecef, lat, lng):
114
118
vector expressed in NED coordinates
115
119
"""
116
120
if abs (lat ) > 90 :
117
- raise ValueError (' latitude should be -90º <= latitude <= 90º' )
121
+ raise ValueError (" latitude should be -90º <= latitude <= 90º" )
118
122
119
123
if abs (lng ) > 180 :
120
- raise ValueError (' longitude should be -180º <= longitude <= 180º' )
124
+ raise ValueError (" longitude should be -180º <= longitude <= 180º" )
121
125
122
126
lat = deg2rad (lat )
123
127
lng = deg2rad (lng )
124
128
125
- Lne = array ([[- sin (lat ) * cos (lng ), - sin (lat ) * sin (lng ), cos (lat )],
126
- [- sin (lng ), cos (lng ), 0 ],
127
- [- cos (lat ) * cos (lng ), - cos (lat ) * sin (lng ), - sin (lat )]])
129
+ Lne = array (
130
+ [
131
+ [- sin (lat ) * cos (lng ), - sin (lat ) * sin (lng ), cos (lat )],
132
+ [- sin (lng ), cos (lng ), 0 ],
133
+ [- cos (lat ) * cos (lng ), - cos (lat ) * sin (lng ), - sin (lat )],
134
+ ]
135
+ )
128
136
129
137
v_ned = Lne .dot (v_ecef )
130
138
@@ -152,24 +160,30 @@ def body2ned(v_body, theta, phi, psi):
152
160
v_ned : array_like
153
161
vector expressed in local horizon (NED) coordinates
154
162
"""
155
- if abs (theta ) > np .pi / 2 :
156
- raise ValueError (' theta should be -pi/2 <= theta <= pi/2' )
163
+ if abs (theta ) > np .pi / 2 :
164
+ raise ValueError (" theta should be -pi/2 <= theta <= pi/2" )
157
165
158
166
if abs (phi ) > np .pi :
159
- raise ValueError ('phi should be -pi <= phi <= pi' )
160
-
161
- if not 0 <= psi <= 2 * np .pi :
162
- raise ValueError ('psi should be 0 <= psi <= 2*pi' )
163
-
164
- Lnb = array ([[cos (theta ) * cos (psi ),
165
- sin (phi ) * sin (theta ) * cos (psi ) - cos (phi ) * sin (psi ),
166
- cos (phi ) * sin (theta ) * cos (psi ) + sin (phi ) * sin (psi )],
167
- [cos (theta ) * sin (psi ),
168
- sin (phi ) * sin (theta ) * sin (psi ) + cos (phi ) * cos (psi ),
169
- cos (phi ) * sin (theta ) * sin (psi ) - sin (phi ) * cos (psi )],
170
- [- sin (theta ),
171
- sin (phi ) * cos (theta ),
172
- cos (phi ) * cos (theta )]])
167
+ raise ValueError ("phi should be -pi <= phi <= pi" )
168
+
169
+ if not 0 <= psi <= 2 * np .pi :
170
+ raise ValueError ("psi should be 0 <= psi <= 2*pi" )
171
+
172
+ Lnb = array (
173
+ [
174
+ [
175
+ cos (theta ) * cos (psi ),
176
+ sin (phi ) * sin (theta ) * cos (psi ) - cos (phi ) * sin (psi ),
177
+ cos (phi ) * sin (theta ) * cos (psi ) + sin (phi ) * sin (psi ),
178
+ ],
179
+ [
180
+ cos (theta ) * sin (psi ),
181
+ sin (phi ) * sin (theta ) * sin (psi ) + cos (phi ) * cos (psi ),
182
+ cos (phi ) * sin (theta ) * sin (psi ) - sin (phi ) * cos (psi ),
183
+ ],
184
+ [- sin (theta ), sin (phi ) * cos (theta ), cos (phi ) * cos (theta )],
185
+ ]
186
+ )
173
187
174
188
v_ned = Lnb .dot (v_body )
175
189
@@ -197,24 +211,30 @@ def ned2body(v_ned, theta, phi, psi):
197
211
v_body: array-like
198
212
vector expressed in body coordinates
199
213
"""
200
- if abs (theta ) > np .pi / 2 :
201
- raise ValueError (' theta should be -pi/2 <= theta <= pi/2' )
214
+ if abs (theta ) > np .pi / 2 :
215
+ raise ValueError (" theta should be -pi/2 <= theta <= pi/2" )
202
216
203
217
if abs (phi ) > np .pi :
204
- raise ValueError ('phi should be -pi <= phi <= pi' )
205
-
206
- if not 0 <= psi <= 2 * np .pi :
207
- raise ValueError ('psi should be 0 <= psi <= 2*pi' )
208
-
209
- Lbn = array ([[cos (theta ) * cos (psi ),
210
- cos (theta ) * sin (psi ),
211
- - sin (theta )],
212
- [sin (phi ) * sin (theta ) * cos (psi ) - cos (phi ) * sin (psi ),
213
- sin (phi ) * sin (theta ) * sin (psi ) + cos (phi ) * cos (psi ),
214
- sin (phi ) * cos (theta )],
215
- [cos (phi ) * sin (theta ) * cos (psi ) + sin (phi ) * sin (psi ),
216
- cos (phi ) * sin (theta ) * sin (psi ) - sin (phi ) * cos (psi ),
217
- cos (phi ) * cos (theta )]])
218
+ raise ValueError ("phi should be -pi <= phi <= pi" )
219
+
220
+ if not 0 <= psi <= 2 * np .pi :
221
+ raise ValueError ("psi should be 0 <= psi <= 2*pi" )
222
+
223
+ Lbn = array (
224
+ [
225
+ [cos (theta ) * cos (psi ), cos (theta ) * sin (psi ), - sin (theta )],
226
+ [
227
+ sin (phi ) * sin (theta ) * cos (psi ) - cos (phi ) * sin (psi ),
228
+ sin (phi ) * sin (theta ) * sin (psi ) + cos (phi ) * cos (psi ),
229
+ sin (phi ) * cos (theta ),
230
+ ],
231
+ [
232
+ cos (phi ) * sin (theta ) * cos (psi ) + sin (phi ) * sin (psi ),
233
+ cos (phi ) * sin (theta ) * sin (psi ) - sin (phi ) * cos (psi ),
234
+ cos (phi ) * cos (theta ),
235
+ ],
236
+ ]
237
+ )
218
238
219
239
v_body = Lbn .dot (v_ned )
220
240
@@ -239,15 +259,19 @@ def body2wind(v_body, alpha, beta):
239
259
v_wind : array_like
240
260
vector expressed in wind coordinates
241
261
"""
242
- if abs (alpha ) > np .pi / 2 :
243
- raise ValueError (' alpha should be -pi/2 <= alpha <= pi/2' )
262
+ if abs (alpha ) > np .pi / 2 :
263
+ raise ValueError (" alpha should be -pi/2 <= alpha <= pi/2" )
244
264
245
265
if abs (beta ) > np .pi :
246
- raise ValueError (' beta should be -pi <= beta <= pi' )
266
+ raise ValueError (" beta should be -pi <= beta <= pi" )
247
267
248
- Lwb = array ([[cos (alpha ) * cos (beta ), sin (beta ), sin (alpha ) * cos (beta )],
249
- [- cos (alpha ) * sin (beta ), cos (beta ), - sin (alpha ) * sin (beta )],
250
- [- sin (alpha ), 0 , cos (alpha )]])
268
+ Lwb = array (
269
+ [
270
+ [cos (alpha ) * cos (beta ), sin (beta ), sin (alpha ) * cos (beta )],
271
+ [- cos (alpha ) * sin (beta ), cos (beta ), - sin (alpha ) * sin (beta )],
272
+ [- sin (alpha ), 0 , cos (alpha )],
273
+ ]
274
+ )
251
275
252
276
v_wind = Lwb .dot (v_body )
253
277
@@ -272,19 +296,19 @@ def wind2body(v_wind, alpha, beta):
272
296
v_body : array_like
273
297
vector expressed in body coordinates
274
298
"""
275
- if abs (alpha ) > np .pi / 2 :
276
- raise ValueError (' alpha should be -pi/2 <= alpha <= pi/2' )
299
+ if abs (alpha ) > np .pi / 2 :
300
+ raise ValueError (" alpha should be -pi/2 <= alpha <= pi/2" )
277
301
278
302
if abs (beta ) > np .pi :
279
- raise ValueError (' beta should be -pi <= beta <= pi' )
303
+ raise ValueError (" beta should be -pi <= beta <= pi" )
280
304
281
- Lbw = array ([[ cos ( alpha ) * cos ( beta ),
282
- - cos ( alpha ) * sin ( beta ),
283
- - sin (alpha )],
284
- [sin (beta ), cos (beta ), 0 ],
285
- [ sin (alpha ) * cos (beta ),
286
- - sin ( alpha ) * sin ( beta ),
287
- cos ( alpha )]] )
305
+ Lbw = array (
306
+ [
307
+ [ cos ( alpha ) * cos ( beta ), - cos ( alpha ) * sin ( beta ), - sin (alpha )],
308
+ [sin (beta ), cos (beta ), 0 ],
309
+ [ sin ( alpha ) * cos ( beta ), - sin (alpha ) * sin (beta ), cos ( alpha )] ,
310
+ ]
311
+ )
288
312
289
313
v_body = Lbw .dot (v_wind )
290
314
@@ -315,10 +339,10 @@ def az_elev_dist(lla, lla_ref):
315
339
lat_ref , lng_ref , h_ref = lla_ref
316
340
317
341
if abs (lat ) > 90 or abs (lat_ref ) > 90 :
318
- raise ValueError (' latitude should be -90º <= latitude <= 90º' )
342
+ raise ValueError (" latitude should be -90º <= latitude <= 90º" )
319
343
320
344
if abs (lng ) > 180 or abs (lng_ref ) > 180 :
321
- raise ValueError (' longitude should be -180º <= longitude <= 180º' )
345
+ raise ValueError (" longitude should be -180º <= longitude <= 180º" )
322
346
323
347
v = lla2ecef (lat , lng , h ) - lla2ecef (lat_ref , lng_ref , h_ref )
324
348
@@ -330,8 +354,9 @@ def az_elev_dist(lla, lla_ref):
330
354
if v_unit_ned [0 ] == v_unit_ned [1 ] == 0 :
331
355
elevation = np .pi / 2
332
356
else :
333
- elevation = np .arctan (- v_unit_ned [2 ] / np .sqrt (v_unit_ned [0 ]** 2 +
334
- v_unit_ned [1 ]** 2 ))
357
+ elevation = np .arctan (
358
+ - v_unit_ned [2 ] / np .sqrt (v_unit_ned [0 ] ** 2 + v_unit_ned [1 ] ** 2 )
359
+ )
335
360
336
361
distance = np .linalg .norm (v )
337
362
0 commit comments