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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//! Module to handle common constants, coordinate types, and utility functions shared across
//! GP parsing and SGP4 propagation.
// ------------------
// External Libraries
// ------------------
use PI;
// ------------------
// Internal Libraries
// ------------------
// -------
// Structs
// -------
/// World Geodetic System (WGS) parameters
///
/// This struct contains the important Earth parameters defined by different WGS
/// standards (e.g. WGS-72, WGS-84).
///
/// # Examples
/// ```rust
/// use mako_sgp4::common::WGS72;
///
/// // WGS-72 is the default Earth model for TLE / SGP4
/// let wgs = WGS72;
/// assert!((wgs.mu - 398600.8).abs() < 1e-9);
/// assert!((wgs.r_earth_eq - 6378.135).abs() < 1e-9);
/// ```
///
/// # References
/// - [Revisiting Spacetrack Report #3: Rev 3 by Vallado et al](https://celestrak.org/publications/AIAA/2006-6753/AIAA-2006-6753-Rev3.pdf)
/// Satellite state vector
///
/// Position \[km\] and velocity \[km/s\] of a satellite in a specified coordinate frame.
/// SGP4 propagation returns this type in [`CoordinateFrame::TEME`].
///
/// # Examples
/// ```rust
/// use mako_sgp4::common::{CoordinateFrame, StateVector};
///
/// // Define a TEME state (position in km, velocity in km/s)
/// let state = StateVector {
/// r_x: 1.0,
/// r_y: 0.0,
/// r_z: 0.0,
/// v_x: 0.0,
/// v_y: 7.5,
/// v_z: 0.0,
/// coordinate_frame: CoordinateFrame::TEME,
/// };
///
/// // Assert the frame used by SGP4
/// assert_eq!(state.coordinate_frame, CoordinateFrame::TEME);
/// ```
///
/// # References
// -----
// Enums
// -----
/// Coordinate frames
///
/// Represents the coordinate frame used for a [`StateVector`].
///
/// # Examples
/// ```rust
/// use mako_sgp4::common::CoordinateFrame;
///
/// // SGP4 state vectors are TEME; J2000 is the enum default
/// let frame_teme = CoordinateFrame::TEME;
/// let frame_j2000 = CoordinateFrame::J2000;
///
/// assert_eq!(frame_j2000, CoordinateFrame::default());
/// assert_ne!(frame_teme, frame_j2000);
/// ```
///
/// # References
// ------
// Traits
// ------
// ---------
// Constants
// ---------
/// Fundamental and derived constants for WGS-72
///
/// Earth model parameters used as the default for TLE/GP processing with SGP4.
///
/// - `mu`: 398600.8 - standard gravitational parameter \[km^3 / s^2\]
/// - `r_earth_eq`: 6378.135 - Earth's equatorial radius \[km\]
/// - `j2`: 0.001082616 - second zonal harmonic (Earth's oblateness)
/// - `k2`: 0.000541308 - `0.5 * j2` \[Earth radii^2\]
/// - `j3`: -0.00000253881 - third zonal harmonic (pear-shaped component)
/// - `j4`: -0.00000165597 - fourth zonal harmonic
/// - `k4`: 0.00000062098875 - `-3/8 * j4` \[Earth radii^4\]
/// - `ke`: 0.07436691613317 - `60 * sqrt(mu / r_earth_eq^3)`, square root of `mu` \[Earth radii^1.5 / min\]
///
/// # Examples
/// ```rust
/// use mako_sgp4::common::WGS72;
///
/// // TLE / SGP4 default Earth model
/// assert!((WGS72.mu - 398600.8).abs() < 1e-9);
/// ```
///
/// # References
/// - [Revisiting Spacetrack Report #3: Rev 3 by Vallado et al](https://celestrak.org/publications/AIAA/2006-6753/AIAA-2006-6753-Rev3.pdf)
pub const WGS72: Wgs = Wgs ;
/// Fundamental and derived constants for WGS-84
///
/// Earth model parameters for the WGS-84 geodetic system.
///
/// - `mu`: 398600.5 - standard gravitational parameter \[km^3 / s^2\]
/// - `r_earth_eq`: 6378.137 - Earth's equatorial radius \[km\]
/// - `j2`: 0.00108262998905 - second zonal harmonic (Earth's oblateness)
/// - `k2`: 0.000541314994525 - `0.5 * j2` \[Earth radii^2\]
/// - `j3`: -0.00000253215306 - third zonal harmonic (pear-shaped component)
/// - `j4`: -0.00000161098761 - fourth zonal harmonic
/// - `k4`: 0.0000006041203538 - `-3/8 * j4` \[Earth radii^4\]
/// - `ke`: 0.07436685316871 - `60 * sqrt(mu / r_earth_eq^3)`, square root of `mu` \[Earth radii^1.5 / min\]
///
/// # Examples
/// ```rust
/// use mako_sgp4::common::{WGS72, WGS84};
///
/// // WGS-84 differs from the TLE default (WGS-72)
/// assert!((WGS84.mu - 398600.5).abs() < 1e-9);
/// assert_ne!(WGS84.mu, WGS72.mu);
/// ```
///
/// # References
/// - [Revisiting Spacetrack Report #3: Rev 3 by Vallado et al](https://celestrak.org/publications/AIAA/2006-6753/AIAA-2006-6753-Rev3.pdf)
pub const WGS84: Wgs = Wgs ;
// ---------
// Functions
// ---------
/// Convert an angle from degrees to radians
///
/// Multiplies the input angle by `pi / 180`.
///
/// # Arguments
/// * `theta` - The angle in degrees
///
/// # Returns
/// * `theta_rad` - The angle in radians
///
/// # Examples
/// ```rust
/// use std::f64::consts::PI;
/// use mako_sgp4::common::deg2rad;
///
/// // Define a right angle in degrees
/// let theta = 90.0;
///
/// // Convert to radians
/// let theta_rad = deg2rad(theta);
///
/// // Assert 90 deg is pi/2
/// assert!((theta_rad - PI / 2.0).abs() < 1e-12);
/// ```
/// Calculate the orbital period from semi-major axis and gravitational parameter
///
/// Uses Kepler's third law: `T = 2 pi sqrt(a^3 / mu)`, returned in minutes.
///
/// # Arguments
/// * `a` - The semi-major axis \[km\]
/// * `mu` - The standard gravitational parameter \[km^3 / s^2\]
///
/// # Returns
/// * `period` - The period in minutes \[min\]
///
/// # Examples
/// ```rust
/// use mako_sgp4::common::{WGS72, calc_period};
///
/// // Circular orbit at Earth's equatorial radius (WGS-72)
/// let period = calc_period(WGS72.r_earth_eq, WGS72.mu);
///
/// // Period is about 84.5 minutes
/// assert!((period - 84.489).abs() < 1e-3);
/// ```
///
/// # References
/// - [Revisiting Spacetrack Report #3: Rev 3 by Vallado et al](https://celestrak.org/publications/AIAA/2006-6753/AIAA-2006-6753-Rev3.pdf)
// ----------
// Unit Tests
// ----------