Skip to content

Commit a242ba3

Browse files
committed
test naive
1 parent 2c953dd commit a242ba3

3 files changed

Lines changed: 64 additions & 61 deletions

File tree

+matmap3d/greenwichsrt.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
tUT1 = (Jdate - 2451545) / 36525;
1212
% Eqn. 3-47 p. 188
1313
gmst_sec = 67310.54841 + (876600 * 3600 + 8640184.812866) * tUT1 + 0.093104 * tUT1 .^ 2 - 6.2e-6 * tUT1 .^ 3;
14-
% 1/86400 and %(2*pi) implied by units of radians
15-
gst = mod(gmst_sec * (2 * pi) / 86400.0, 2 * pi);
14+
% 1/86400 and 2*pi implied by units of radians
15+
tau = 2*pi;
16+
gst = mod(gmst_sec * tau / 86400.0, tau);
1617

1718
end

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
strategy:
2121
matrix:
22-
release: [R2023b, R2025a]
22+
release: [R2023b, R2025b]
2323

2424
steps:
2525
- uses: actions/checkout@v5

test/TestUnit.m

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
atol = 1e-9
66
rtol = 1e-6
77
angleUnit='d'
8+
89
lat = 42
910
lon = -82
1011
alt = 200
@@ -28,68 +29,72 @@
2829
zl = 4.246579604632881e+06 % aer2ecef
2930

3031
a90 = 90
32+
E
33+
end
34+
35+
36+
methods (TestMethodSetup)
37+
function setupEllipsoid(tc)
38+
tc.E = matmap3d.wgs84Ellipsoid();
39+
end
3140
end
3241

3342

3443
methods(Test)
3544

3645
function test_ellipsoid(tc)
37-
tc.verifyClass(matmap3d.wgs84Ellipsoid(), 'matmap3d.referenceEllipsoid')
46+
tc.verifyClass(tc.E, 'matmap3d.referenceEllipsoid')
3847
end
3948

4049
function 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);
4552
tc.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

6572
end
6673

6774
function 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);
7580
tc.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);
7883
tc.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);
8186
tc.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);
8489
tc.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);
8792
tc.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);
9095
tc.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);
9398
tc.verifyEqual([lt,ln,at], [0,45,-1000], AbsTol=tc.atol, RelTol=tc.rtol)
9499

95100
end
@@ -117,75 +122,68 @@ function test_aer2enu(tc)
117122

118123
function 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
124127
tc.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);
128131
tc.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);
131134
tc.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);
134137
tc.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);
137140
tc.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);
140143
tc.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);
143146
tc.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);
146149
tc.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);
149152
tc.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);
152155
tc.verifyEqual([a,e,r], [tc.az, tc.el, tc.srange], AbsTol=tc.atol, RelTol=tc.rtol)
153156
end
154157

155158
function 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);
160161
tc.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
163164
tc.verifyEqual([a,e,r], [tc.az, tc.el, tc.srange], AbsTol=tc.atol, RelTol=tc.rtol)
164165
end
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);
171171
tc.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
174174
tc.verifyEqual([lt, ln, at],[tc.lat, tc.lon, tc.alt-1], AbsTol=tc.atol, RelTol=tc.rtol)
175175
end
176176

177177

178178
function 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);
183181
tc.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
186184
tc.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);
189187
tc.verifyEqual([e,n,u],[e1,n1,-d])
190188

191189
end
@@ -203,7 +201,6 @@ function test_enu_vector(tc)
203201

204202

205203
function test_lookAtSpheroid(tc)
206-
207204
az5 = [0., 10., 125.];
208205
tilt = [30, 45, 90];
209206

@@ -222,6 +219,7 @@ function test_lookAtSpheroid(tc)
222219
tc.verifyEqual([lat5, lon5, rng5], truth(:).', AbsTol=tc.atol, RelTol=tc.rtol)
223220
end
224221

222+
225223
function test_eci2ecef(tc)
226224
utc = datetime(2019, 1, 4, 12,0,0);
227225
eci = [-2981784; 5207055; 3161595];
@@ -230,17 +228,24 @@ function test_eci2ecef(tc)
230228
end
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+
233239
function test_ecef2eci(tc)
234240
ecef = [-5762640; -1682738; 3156028];
235241
utc = datetime(2019, 1, 4, 12,0,0);
236242
r_eci = matmap3d.ecef2eci(utc, ecef);
237243
tc.verifyEqual(r_eci, [-2981829.07728415; 5207029.04470791; 3161595.0981204], RelTol=1e-5)
238244
end
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);
244249
t = datetime(2000, 1, 1, 12, 0, 0, TimeZone='UTCLeapSeconds');
245250
r_eci = matmap3d.ecef2eci(t, [x;y;z]);
246251
tc.verifyEqual(r_eci, [1158174.72525987; -6272101.9503871; -143.138407305876], RelTol=tc.rtol)
@@ -251,7 +256,7 @@ function test_eci2aer(tc)
251256
eci = [-3.8454e8, -0.5099e8, -0.3255e8];
252257
utc = datetime(1969, 7, 20, 21, 17, 40);
253258
lla = [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));
256261
tc.verifyEqual([a, e, r], [162.548042074738, 55.1223823017527, 384013992.914642], RelTol=tc.rtol)
257262
end
@@ -261,9 +266,6 @@ function test_aer2eci(tc)
261266
lla = [28.4, -80.5, 2.7];
262267
utc = 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));
268270
tc.verifyEqual([x, y, z], [-384538755.067354, -50986804.9565394, -32567306.0200869], RelTol=2e5)
269271
end

0 commit comments

Comments
 (0)