@@ -54,12 +54,12 @@ impl Orbit {
54
54
/// One should expect these errors to be on the order of 1e-12.
55
55
#[ allow( clippy:: too_many_arguments) ]
56
56
pub fn try_keplerian (
57
- sma : f64 ,
57
+ sma_km : f64 ,
58
58
ecc : f64 ,
59
- inc : f64 ,
60
- raan : f64 ,
61
- aop : f64 ,
62
- ta : f64 ,
59
+ inc_deg : f64 ,
60
+ raan_deg : f64 ,
61
+ aop_deg : f64 ,
62
+ ta_deg : f64 ,
63
63
epoch : Epoch ,
64
64
frame : Frame ,
65
65
) -> PhysicsResult < Self > {
@@ -74,14 +74,14 @@ impl Orbit {
74
74
} else {
75
75
ecc
76
76
} ;
77
- let sma = if ecc > 1.0 && sma > 0.0 {
77
+ let sma = if ecc > 1.0 && sma_km > 0.0 {
78
78
warn ! ( "eccentricity > 1 (hyperbolic) BUT SMA > 0 (elliptical): sign of SMA changed" ) ;
79
- sma * -1.0
80
- } else if ecc < 1.0 && sma < 0.0 {
79
+ sma_km * -1.0
80
+ } else if ecc < 1.0 && sma_km < 0.0 {
81
81
warn ! ( "eccentricity < 1 (elliptical) BUT SMA < 0 (hyperbolic): sign of SMA changed" ) ;
82
- sma * -1.0
82
+ sma_km * -1.0
83
83
} else {
84
- sma
84
+ sma_km
85
85
} ;
86
86
if ( sma * ( 1.0 - ecc) ) . abs ( ) < 1e-3 {
87
87
// GMAT errors below one meter. Let's warn for below that, but not panic, might be useful for landing scenarios?
@@ -92,14 +92,14 @@ impl Orbit {
92
92
ParabolicEccentricitySnafu { limit: ECC_EPSILON }
93
93
) ;
94
94
if ecc > 1.0 {
95
- let ta_deg = between_0_360 ( ta ) ;
95
+ let ta_deg = between_0_360 ( ta_deg ) ;
96
96
ensure ! (
97
97
ta_deg <= ( PI - ( 1.0 / ecc) . acos( ) ) . to_degrees( ) ,
98
98
HyperbolicTrueAnomalySnafu { ta_deg }
99
99
) ;
100
100
}
101
101
ensure ! (
102
- ( 1.0 + ecc * ta . to_radians( ) . cos( ) ) . is_finite( ) ,
102
+ ( 1.0 + ecc * ta_deg . to_radians( ) . cos( ) ) . is_finite( ) ,
103
103
InfiniteValueSnafu {
104
104
action: "computing radius of orbit"
105
105
}
@@ -109,28 +109,28 @@ impl Orbit {
109
109
// The conversion algorithm itself comes from GMAT's StateConversionUtil::ComputeKeplToCart
110
110
// NOTE: GMAT supports mean anomaly instead of true anomaly, but only for backward compatibility reasons
111
111
// so it isn't supported here.
112
- let inc = inc . to_radians ( ) ;
113
- let raan = raan . to_radians ( ) ;
114
- let aop = aop . to_radians ( ) ;
115
- let ta = ta . to_radians ( ) ;
116
- let p = sma * ( 1.0 - ecc. powi ( 2 ) ) ;
112
+ let inc_rad = inc_deg . to_radians ( ) ;
113
+ let raan_rad = raan_deg . to_radians ( ) ;
114
+ let aop_rad = aop_deg . to_radians ( ) ;
115
+ let ta_rad = ta_deg . to_radians ( ) ;
116
+ let p_km = sma * ( 1.0 - ecc. powi ( 2 ) ) ;
117
117
118
- ensure ! ( p . abs( ) >= f64 :: EPSILON , ParabolicSemiParamSnafu { p } ) ;
118
+ ensure ! ( p_km . abs( ) >= f64 :: EPSILON , ParabolicSemiParamSnafu { p_km } ) ;
119
119
120
120
// NOTE: At this point GMAT computes 1+ecc**2 and checks whether it's very small.
121
121
// It then reports that the radius may be too large. We've effectively already done
122
122
// this check above (and panicked if needed), so it isn't repeated here.
123
- let radius = p / ( 1.0 + ecc * ta . cos ( ) ) ;
124
- let ( sin_aop_ta, cos_aop_ta) = ( aop + ta ) . sin_cos ( ) ;
125
- let ( sin_inc, cos_inc) = inc . sin_cos ( ) ;
126
- let ( sin_raan, cos_raan) = raan . sin_cos ( ) ;
127
- let ( sin_aop, cos_aop) = aop . sin_cos ( ) ;
123
+ let radius = p_km / ( 1.0 + ecc * ta_rad . cos ( ) ) ;
124
+ let ( sin_aop_ta, cos_aop_ta) = ( aop_rad + ta_rad ) . sin_cos ( ) ;
125
+ let ( sin_inc, cos_inc) = inc_rad . sin_cos ( ) ;
126
+ let ( sin_raan, cos_raan) = raan_rad . sin_cos ( ) ;
127
+ let ( sin_aop, cos_aop) = aop_rad . sin_cos ( ) ;
128
128
let x = radius * ( cos_aop_ta * cos_raan - cos_inc * sin_aop_ta * sin_raan) ;
129
129
let y = radius * ( cos_aop_ta * sin_raan + cos_inc * sin_aop_ta * cos_raan) ;
130
130
let z = radius * sin_aop_ta * sin_inc;
131
- let sqrt_gm_p = ( mu_km3_s2 / p ) . sqrt ( ) ;
132
- let cos_ta_ecc = ta . cos ( ) + ecc;
133
- let sin_ta = ta . sin ( ) ;
131
+ let sqrt_gm_p = ( mu_km3_s2 / p_km ) . sqrt ( ) ;
132
+ let cos_ta_ecc = ta_rad . cos ( ) + ecc;
133
+ let sin_ta = ta_rad . sin ( ) ;
134
134
135
135
let vx = sqrt_gm_p * cos_ta_ecc * ( -sin_aop * cos_raan - cos_inc * sin_raan * cos_aop)
136
136
- sqrt_gm_p * sin_ta * ( cos_aop * cos_raan - cos_inc * sin_raan * sin_aop) ;
@@ -149,31 +149,31 @@ impl Orbit {
149
149
/// Attempts to create a new Orbit from the provided radii of apoapsis and periapsis, in kilometers
150
150
#[ allow( clippy:: too_many_arguments) ]
151
151
pub fn try_keplerian_apsis_radii (
152
- r_a : f64 ,
153
- r_p : f64 ,
154
- inc : f64 ,
155
- raan : f64 ,
156
- aop : f64 ,
157
- ta : f64 ,
152
+ r_a_km : f64 ,
153
+ r_p_km : f64 ,
154
+ inc_deg : f64 ,
155
+ raan_deg : f64 ,
156
+ aop_deg : f64 ,
157
+ ta_deg : f64 ,
158
158
epoch : Epoch ,
159
159
frame : Frame ,
160
160
) -> PhysicsResult < Self > {
161
161
ensure ! (
162
- r_a > f64 :: EPSILON ,
162
+ r_a_km > f64 :: EPSILON ,
163
163
RadiusSnafu {
164
164
action: "radius of apoapsis is negative"
165
165
}
166
166
) ;
167
167
ensure ! (
168
- r_p > f64 :: EPSILON ,
168
+ r_p_km > f64 :: EPSILON ,
169
169
RadiusSnafu {
170
170
action: "radius of periapsis is negative"
171
171
}
172
172
) ;
173
173
// The two checks above ensure that sma > 0
174
- let sma = ( r_a + r_p ) / 2.0 ;
175
- let ecc = r_a / sma - 1.0 ;
176
- Self :: try_keplerian ( sma, ecc, inc , raan , aop , ta , epoch, frame)
174
+ let sma = ( r_a_km + r_p_km ) / 2.0 ;
175
+ let ecc = r_a_km / sma - 1.0 ;
176
+ Self :: try_keplerian ( sma, ecc, inc_deg , raan_deg , aop_deg , ta_deg , epoch, frame)
177
177
}
178
178
179
179
/// Attempts to create a new Orbit around the provided frame from the borrowed state vector
@@ -196,31 +196,37 @@ impl Orbit {
196
196
/// One should expect these errors to be on the order of 1e-12.
197
197
#[ allow( clippy:: too_many_arguments) ]
198
198
pub fn keplerian (
199
- sma : f64 ,
199
+ sma_km : f64 ,
200
200
ecc : f64 ,
201
- inc : f64 ,
202
- raan : f64 ,
203
- aop : f64 ,
204
- ta : f64 ,
201
+ inc_deg : f64 ,
202
+ raan_deg : f64 ,
203
+ aop_deg : f64 ,
204
+ ta_deg : f64 ,
205
205
epoch : Epoch ,
206
206
frame : Frame ,
207
207
) -> Self {
208
- Self :: try_keplerian ( sma, ecc, inc, raan, aop, ta, epoch, frame) . unwrap ( )
208
+ Self :: try_keplerian (
209
+ sma_km, ecc, inc_deg, raan_deg, aop_deg, ta_deg, epoch, frame,
210
+ )
211
+ . unwrap ( )
209
212
}
210
213
211
214
/// Creates a new Orbit from the provided radii of apoapsis and periapsis, in kilometers
212
215
#[ allow( clippy:: too_many_arguments) ]
213
216
pub fn keplerian_apsis_radii (
214
- r_a : f64 ,
215
- r_p : f64 ,
216
- inc : f64 ,
217
- raan : f64 ,
218
- aop : f64 ,
219
- ta : f64 ,
217
+ r_a_km : f64 ,
218
+ r_p_km : f64 ,
219
+ inc_deg : f64 ,
220
+ raan_deg : f64 ,
221
+ aop_deg : f64 ,
222
+ ta_deg : f64 ,
220
223
epoch : Epoch ,
221
224
frame : Frame ,
222
225
) -> Self {
223
- Self :: try_keplerian_apsis_radii ( r_a, r_p, inc, raan, aop, ta, epoch, frame) . unwrap ( )
226
+ Self :: try_keplerian_apsis_radii (
227
+ r_a_km, r_p_km, inc_deg, raan_deg, aop_deg, ta_deg, epoch, frame,
228
+ )
229
+ . unwrap ( )
224
230
}
225
231
226
232
/// Initializes a new orbit from the Keplerian orbital elements using the mean anomaly instead of the true anomaly.
0 commit comments