55atol = 1e-9
66rtol = 1e-6
77angleUnit = ' d'
8+
89lat = 42
910lon = - 82
1011alt = 200
2829zl = 4 .246579604632881e+ 06 % aer2ecef
2930
3031a90 = 90
32+ E
33+ end
34+
35+
36+ methods (TestMethodSetup )
37+ function setupEllipsoid(tc )
38+ tc.E = matmap3d .wgs84Ellipsoid();
39+ end
3140end
3241
3342
3443methods (Test )
3544
3645function test_ellipsoid(tc )
37- tc .verifyClass(matmap3d .wgs84Ellipsoid() , ' matmap3d.referenceEllipsoid' )
46+ tc .verifyClass(tc . E , ' matmap3d.referenceEllipsoid' )
3847end
3948
4049function test_geodetic2ecef(tc )
4150
42- E = matmap3d .wgs84Ellipsoid();
43-
44- [x ,y ,z ] = matmap3d .geodetic2ecef(E , tc .lat , tc .lon , tc .alt , tc .angleUnit );
51+ [x ,y ,z ] = matmap3d .geodetic2ecef(tc .E , tc .lat , tc .lon , tc .alt , tc .angleUnit );
4552tc .verifyEqual([x ,y ,z ], [tc .x0 , tc .y0 , tc .z0 ], AbsTol= tc .atol , RelTol= tc .rtol )
4653
4754[x ,y ,z ] = matmap3d .geodetic2ecef([], 0 ,0 ,-1 );
48- tc .verifyEqual([x ,y ,z ], [E .SemimajorAxis - 1 ,0 ,0 ], AbsTol= tc .atol , RelTol= tc .rtol )
55+ tc .verifyEqual([x ,y ,z ], [tc . E .SemimajorAxis - 1 ,0 ,0 ], AbsTol= tc .atol , RelTol= tc .rtol )
4956
50- [x ,y ,z ] = matmap3d .geodetic2ecef(E , 0 ,90 ,-1 );
51- tc .verifyEqual([x ,y ,z ], [0 , E .SemimajorAxis - 1 ,0 ], AbsTol= tc .atol , RelTol= tc .rtol )
57+ [x ,y ,z ] = matmap3d .geodetic2ecef(tc . E , 0 ,90 ,-1 );
58+ tc .verifyEqual([x ,y ,z ], [0 , tc . E .SemimajorAxis - 1 ,0 ], AbsTol= tc .atol , RelTol= tc .rtol )
5259
53- [x ,y ,z ] = matmap3d .geodetic2ecef(E , 0 ,-90 ,-1 );
54- tc .verifyEqual([x ,y ,z ], [0 , - E .SemimajorAxis + 1 ,0 ], AbsTol= tc .atol , RelTol= tc .rtol )
60+ [x ,y ,z ] = matmap3d .geodetic2ecef(tc . E , 0 ,-90 ,-1 );
61+ tc .verifyEqual([x ,y ,z ], [0 , - tc . E .SemimajorAxis + 1 ,0 ], AbsTol= tc .atol , RelTol= tc .rtol )
5562
56- [x ,y ,z ] = matmap3d .geodetic2ecef(E , 90 ,0 ,-1 );
57- tc .verifyEqual([x ,y ,z ], [0 , 0 , E .SemiminorAxis - 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
63+ [x ,y ,z ] = matmap3d .geodetic2ecef(tc . E , 90 ,0 ,-1 );
64+ tc .verifyEqual([x ,y ,z ], [0 , 0 , tc . E .SemiminorAxis - 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
5865
59- [x ,y ,z ] = matmap3d .geodetic2ecef(E , 90 ,15 ,-1 );
60- tc .verifyEqual([x ,y ,z ], [0 ,0 , E .SemiminorAxis - 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
66+ [x ,y ,z ] = matmap3d .geodetic2ecef(tc . E , 90 ,15 ,-1 );
67+ tc .verifyEqual([x ,y ,z ], [0 ,0 , tc . E .SemiminorAxis - 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
6168
62- [x ,y ,z ] = matmap3d .geodetic2ecef(E , - 90 ,0 ,-1 );
63- tc .verifyEqual([x ,y ,z ], [0 ,0 , - E .SemiminorAxis + 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
69+ [x ,y ,z ] = matmap3d .geodetic2ecef(tc . E , - 90 ,0 ,-1 );
70+ tc .verifyEqual([x ,y ,z ], [0 ,0 , - tc . E .SemiminorAxis + 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
6471
6572end
6673
6774function test_ecef2geodetic(tc )
6875
69- E = matmap3d .wgs84Ellipsoid();
76+ ea = tc .E .SemimajorAxis ;
77+ eb = tc .E .SemiminorAxis ;
7078
71- ea = E .SemimajorAxis ;
72- eb = E .SemiminorAxis ;
73-
74- [lt , ln , at ] = matmap3d .ecef2geodetic(E , tc .x0 , tc .y0 , tc .z0 , tc .angleUnit );
79+ [lt , ln , at ] = matmap3d .ecef2geodetic(tc .E , tc .x0 , tc .y0 , tc .z0 , tc .angleUnit );
7580tc .verifyEqual([lt , ln , at ], [tc .lat , tc .lon , tc .alt ], AbsTol= tc .atol , RelTol= tc .rtol )
7681
7782[lt , ln , at ] = matmap3d .ecef2geodetic([], ea - 1 , 0 , 0 );
7883tc .verifyEqual([lt , ln , at ], [0 , 0 , - 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
7984
80- [lt , ln , at ] = matmap3d .ecef2geodetic(E , 0 , ea - 1 , 0 );
85+ [lt , ln , at ] = matmap3d .ecef2geodetic(tc . E , 0 , ea - 1 , 0 );
8186tc .verifyEqual([lt , ln , at ], [0 , 90 , - 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
8287
83- [lt , ln , at ] = matmap3d .ecef2geodetic(E , 0 , 0 , eb - 1 );
88+ [lt , ln , at ] = matmap3d .ecef2geodetic(tc . E , 0 , 0 , eb - 1 );
8489tc .verifyEqual([lt , ln , at ], [90 , 0 , - 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
8590
86- [lt , ln , at ] = matmap3d .ecef2geodetic(E , 0 , 0 , - eb + 1 );
91+ [lt , ln , at ] = matmap3d .ecef2geodetic(tc . E , 0 , 0 , - eb + 1 );
8792tc .verifyEqual([lt , ln , at ], [-90 , 0 , - 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
8893
89- [lt , ln , at ] = matmap3d .ecef2geodetic(E , - ea + 1 , 0 , 0 );
94+ [lt , ln , at ] = matmap3d .ecef2geodetic(tc . E , - ea + 1 , 0 , 0 );
9095tc .verifyEqual([lt , ln , at ], [0 , 180 , - 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
9196
92- [lt , ln , at ] = matmap3d .ecef2geodetic(E , (ea - 1000 )/sqrt(2 ), (ea - 1000 )/sqrt(2 ), 0 );
97+ [lt , ln , at ] = matmap3d .ecef2geodetic(tc . E , (ea - 1000 )/sqrt(2 ), (ea - 1000 )/sqrt(2 ), 0 );
9398tc .verifyEqual([lt ,ln ,at ], [0 ,45 ,-1000 ], AbsTol= tc .atol , RelTol= tc .rtol )
9499
95100end
@@ -117,75 +122,68 @@ function test_aer2enu(tc)
117122
118123function test_ecef2aer(tc )
119124
120- E = matmap3d .wgs84Ellipsoid();
121-
122- [a , e , r ] = matmap3d .ecef2aer(tc .xl , tc .yl , tc .zl , tc .lat , tc .lon , tc .alt , E , tc .angleUnit );
125+ [a , e , r ] = matmap3d .ecef2aer(tc .xl , tc .yl , tc .zl , tc .lat , tc .lon , tc .alt , tc .E , tc .angleUnit );
123126% round-trip
124127tc .verifyEqual([a ,e ,r ], [tc .az , tc .el , tc .srange ], AbsTol= tc .atol , RelTol= tc .rtol )
125128
126129% singularity check
127- [a , e , r ] = matmap3d .ecef2aer(E .SemimajorAxis - 1 , 0 , 0 , 0 ,0 ,0 , E , tc .angleUnit );
130+ [a , e , r ] = matmap3d .ecef2aer(tc . E .SemimajorAxis - 1 , 0 , 0 , 0 ,0 ,0 , tc . E , tc .angleUnit );
128131tc .verifyEqual([a ,e ,r ], [0 , - tc .a90 , 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
129132
130- [a , e , r ] = matmap3d .ecef2aer(-E .SemimajorAxis + 1 , 0 , 0 , 0 , 2 * tc .a90 ,0 , E , tc .angleUnit );
133+ [a , e , r ] = matmap3d .ecef2aer(-tc . E .SemimajorAxis + 1 , 0 , 0 , 0 , 2 * tc .a90 ,0 , tc . E , tc .angleUnit );
131134tc .verifyEqual([a ,e ,r ], [0 , - tc .a90 , 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
132135
133- [a , e , r ] = matmap3d .ecef2aer(0 , E .SemimajorAxis - 1 , 0 ,0 , tc .a90 ,0 , E , tc .angleUnit );
136+ [a , e , r ] = matmap3d .ecef2aer(0 , tc . E .SemimajorAxis - 1 , 0 ,0 , tc .a90 ,0 , tc . E , tc .angleUnit );
134137tc .verifyEqual([a ,e ,r ], [0 , - tc .a90 , 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
135138
136- [a , e , r ] = matmap3d .ecef2aer(0 , - E .SemimajorAxis + 1 , 0 ,0 , - tc .a90 ,0 , E , tc .angleUnit );
139+ [a , e , r ] = matmap3d .ecef2aer(0 , - tc . E .SemimajorAxis + 1 , 0 ,0 , - tc .a90 ,0 , tc . E , tc .angleUnit );
137140tc .verifyEqual([a ,e ,r ], [0 , - tc .a90 , 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
138141
139- [a , e , r ] = matmap3d .ecef2aer(0 , 0 , E .SemiminorAxis - 1 , tc .a90 , 0 , 0 , E , tc .angleUnit );
142+ [a , e , r ] = matmap3d .ecef2aer(0 , 0 , tc . E .SemiminorAxis - 1 , tc .a90 , 0 , 0 , tc . E , tc .angleUnit );
140143tc .verifyEqual([a ,e ,r ], [0 , - tc .a90 , 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
141144
142- [a , e , r ] = matmap3d .ecef2aer(0 , 0 , - E .SemiminorAxis + 1 ,-tc .a90 ,0 ,0 , E , tc .angleUnit );
145+ [a , e , r ] = matmap3d .ecef2aer(0 , 0 , - tc . E .SemiminorAxis + 1 ,-tc .a90 ,0 ,0 , tc . E , tc .angleUnit );
143146tc .verifyEqual([a ,e ,r ], [0 , - tc .a90 , 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
144147
145- [a , e , r ] = matmap3d .ecef2aer((E .SemimajorAxis - 1000 )/sqrt(2 ), (E .SemimajorAxis - 1000 )/sqrt(2 ), 0 , 0 , 45 , 0 );
148+ [a , e , r ] = matmap3d .ecef2aer((tc . E .SemimajorAxis - 1000 )/sqrt(2 ), (tc . E .SemimajorAxis - 1000 )/sqrt(2 ), 0 , 0 , 45 , 0 );
146149tc .verifyEqual([a ,e ,r ],[0 ,-90 ,1000 ], AbsTol= tc .atol , RelTol= tc .rtol )
147150
148- [x ,y ,z ] = matmap3d .aer2ecef(tc .az , tc .el , tc .srange , tc .lat , tc .lon , tc .alt , E , tc .angleUnit );
151+ [x ,y ,z ] = matmap3d .aer2ecef(tc .az , tc .el , tc .srange , tc .lat , tc .lon , tc .alt , tc . E , tc .angleUnit );
149152tc .verifyEqual([x ,y ,z ], [tc .xl , tc .yl , tc .zl ], AbsTol= tc .atol , RelTol= tc .rtol )
150153
151- [a ,e ,r ] = matmap3d .ecef2aer(x ,y ,z , tc .lat , tc .lon , tc .alt , E , tc .angleUnit );
154+ [a ,e ,r ] = matmap3d .ecef2aer(x ,y ,z , tc .lat , tc .lon , tc .alt , tc . E , tc .angleUnit );
152155tc .verifyEqual([a ,e ,r ], [tc .az , tc .el , tc .srange ], AbsTol= tc .atol , RelTol= tc .rtol )
153156end
154157
155158function test_geodetic2aer(tc )
156159
157- E = matmap3d .wgs84Ellipsoid();
158-
159- [lt ,ln ,at ] = matmap3d .aer2geodetic(tc .az , tc .el , tc .srange , tc .lat , tc .lon , tc .alt , E , tc .angleUnit );
160+ [lt ,ln ,at ] = matmap3d .aer2geodetic(tc .az , tc .el , tc .srange , tc .lat , tc .lon , tc .alt , tc .E , tc .angleUnit );
160161tc .verifyEqual([lt ,ln ,at ], [tc .lat1 , tc .lon1 , tc .alt1 ], AbsTol= 2 * tc .atol_dist )
161162
162- [a , e , r ] = matmap3d .geodetic2aer(lt ,ln ,at , tc .lat , tc .lon , tc .alt , E , tc .angleUnit ); % round-trip
163+ [a , e , r ] = matmap3d .geodetic2aer(lt ,ln ,at , tc .lat , tc .lon , tc .alt , tc . E , tc .angleUnit ); % round-trip
163164tc .verifyEqual([a ,e ,r ], [tc .az , tc .el , tc .srange ], AbsTol= tc .atol , RelTol= tc .rtol )
164165end
165166
166- function test_geodetic2enu(tc )
167167
168- E = matmap3d .wgs84Ellipsoid();
168+ function test_geodetic2enu( tc )
169169
170- [e , n , u ] = matmap3d .geodetic2enu(tc .lat , tc .lon , tc .alt - 1 , tc .lat , tc .lon , tc .alt , E , tc .angleUnit );
170+ [e , n , u ] = matmap3d .geodetic2enu(tc .lat , tc .lon , tc .alt - 1 , tc .lat , tc .lon , tc .alt , tc . E , tc .angleUnit );
171171tc .verifyEqual([e ,n ,u ], [0 ,0 ,-1 ], AbsTol= tc .atol , RelTol= tc .rtol )
172172
173- [lt , ln , at ] = matmap3d .enu2geodetic(e ,n ,u ,tc .lat ,tc .lon ,tc .alt , E , tc .angleUnit ); % round-trip
173+ [lt , ln , at ] = matmap3d .enu2geodetic(e ,n ,u ,tc .lat ,tc .lon ,tc .alt , tc . E , tc .angleUnit ); % round-trip
174174tc .verifyEqual([lt , ln , at ],[tc .lat , tc .lon , tc .alt - 1 ], AbsTol= tc .atol , RelTol= tc .rtol )
175175end
176176
177177
178178function test_enu2ecef(tc )
179179
180- E = matmap3d .wgs84Ellipsoid();
181-
182- [x , y , z ] = matmap3d .enu2ecef(tc .er , tc .nr , tc .ur , tc .lat ,tc .lon ,tc .alt , E , tc .angleUnit );
180+ [x , y , z ] = matmap3d .enu2ecef(tc .er , tc .nr , tc .ur , tc .lat ,tc .lon ,tc .alt , tc .E , tc .angleUnit );
183181tc .verifyEqual([x ,y ,z ],[tc .xl , tc .yl , tc .zl ], AbsTol= tc .atol , RelTol= tc .rtol )
184182
185- [e ,n ,u ] = matmap3d .ecef2enu(x ,y ,z ,tc .lat ,tc .lon ,tc .alt , E , tc .angleUnit ); % round-trip
183+ [e ,n ,u ] = matmap3d .ecef2enu(x ,y ,z ,tc .lat ,tc .lon ,tc .alt , tc . E , tc .angleUnit ); % round-trip
186184tc .verifyEqual([e ,n ,u ],[tc .er , tc .nr , tc .ur ], AbsTol= tc .atol , RelTol= tc .rtol )
187185
188- [n1 , e1 , d ] = matmap3d .ecef2ned(x ,y ,z ,tc .lat ,tc .lon ,tc .alt , E , tc .angleUnit );
186+ [n1 , e1 , d ] = matmap3d .ecef2ned(x ,y ,z ,tc .lat ,tc .lon ,tc .alt , tc . E , tc .angleUnit );
189187tc .verifyEqual([e ,n ,u ],[e1 ,n1 ,-d ])
190188
191189end
@@ -203,7 +201,6 @@ function test_enu_vector(tc)
203201
204202
205203function test_lookAtSpheroid(tc )
206-
207204az5 = [0 ., 10 ., 125 .];
208205tilt = [30 , 45 , 90 ];
209206
@@ -222,6 +219,7 @@ function test_lookAtSpheroid(tc)
222219tc .verifyEqual([lat5 , lon5 , rng5 ], truth(: ).' , AbsTol= tc .atol , RelTol= tc .rtol )
223220end
224221
222+
225223function test_eci2ecef(tc )
226224utc = datetime(2019 , 1 , 4 , 12 ,0 ,0 );
227225eci = [-2981784 ; 5207055 ; 3161595 ];
@@ -230,17 +228,24 @@ function test_eci2ecef(tc)
230228end
231229
232230
231+ function test_naive(tc )
232+ utc = datetime(2019 , 1 , 4 , 12 ,0 ,0 );
233+ [x ,y ,z ] = matmap3d .ecef2eci_naive(utc , tc .x0 , tc .y0 , tc .z0 );
234+ [x1 ,y1 ,z1 ] = matmap3d .eci2ecef_naive(utc , x ,y ,z );
235+ tc .verifyEqual([x1 ,y1 ,z1 ], [tc .x0 ,tc .y0 ,tc .z0 ], RelTol= 1e-9 )
236+ end
237+
238+
233239function test_ecef2eci(tc )
234240ecef = [-5762640 ; - 1682738 ; 3156028 ];
235241utc = datetime(2019 , 1 , 4 , 12 ,0 ,0 );
236242r_eci = matmap3d .ecef2eci(utc , ecef );
237243tc .verifyEqual(r_eci , [-2981829.07728415 ; 5207029.04470791 ; 3161595.0981204 ], RelTol= 1e-5 )
238244end
239245
240- function test_ecef2eci_null(tc )
241- E = matmap3d .wgs84Ellipsoid();
242246
243- [x , y , z ] = matmap3d .geodetic2ecef(E , 0 , 0 , 0 );
247+ function test_ecef2eci_null(tc )
248+ [x , y , z ] = matmap3d .geodetic2ecef(tc .E , 0 , 0 , 0 );
244249t = datetime(2000 , 1 , 1 , 12 , 0 , 0 , TimeZone= ' UTCLeapSeconds' );
245250r_eci = matmap3d .ecef2eci(t , [x ;y ;z ]);
246251tc .verifyEqual(r_eci , [1158174.72525987 ; - 6272101.9503871 ; - 143.138407305876 ], RelTol= tc .rtol )
@@ -251,7 +256,7 @@ function test_eci2aer(tc)
251256eci = [-3.8454e8 , - 0.5099e8 , - 0.3255e8 ];
252257utc = datetime(1969 , 7 , 20 , 21 , 17 , 40 );
253258lla = [28.4 , - 80.5 , 2.7 ];
254- % aer = eci2aer(eci, datevec(utc), lla);
259+
255260[a , e , r ] = matmap3d .eci2aer(utc , eci(1 ), eci(2 ), eci(3 ), lla(1 ), lla(2 ), lla(3 ));
256261tc .verifyEqual([a , e , r ], [162.548042074738 , 55.1223823017527 , 384013992.914642 ], RelTol= tc .rtol )
257262end
@@ -261,9 +266,6 @@ function test_aer2eci(tc)
261266lla = [28.4 , - 80.5 , 2.7 ];
262267utc = datetime(1969 , 7 , 20 , 21 , 17 , 40 );
263268
264- % [x,y,z] = aer2ecef(aer(1), aer(2), aer(3), lla(1), lla(2), lla(3), wgs84Ellipsoid());
265- % eci = ecef2eci(utc, [x;y;z]);
266-
267269[x ,y ,z ] = matmap3d .aer2eci(utc , aer(1 ), aer(2 ), aer(3 ), lla(1 ), lla(2 ), lla(3 ));
268270tc .verifyEqual([x , y , z ], [-384538755.067354 , - 50986804.9565394 , - 32567306.0200869 ], RelTol= 2e5 )
269271end
0 commit comments