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
/*
Nyx, blazing fast astrodynamics
Copyright (C) 2021 Christopher Rabotin <christopher.rabotin@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use super::NyxError;
use std::str::FromStr;
/// Common state parameters
#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum StateParameter {
/// Argument of Latitude (deg)
AoL,
/// Argument of Periapse (deg)
AoP,
/// Apoapsis, shortcut for TA == 180.0
Apoapsis,
/// Radius of apoapsis (km)
ApoapsisRadius,
/// B-Plane B⋅R
BdotR,
/// B-Plane B⋅T
BdotT,
/// B-Plane LTOF
BLTOF,
/// C_3 in (km/s)^2
C3,
/// Coefficient of drag
Cd,
/// Coefficient of reflectivity
Cr,
/// Declination (deg)
Declination,
/// The epoch of the state
Epoch,
/// Eccentric anomaly (deg)
EccentricAnomaly,
/// Eccentricity (no unit)
Eccentricity,
/// Specific energy
Energy,
/// Flight path angle (deg)
FlightPathAngle,
/// fuel mass in kilograms
FuelMass,
/// Geodetic height (km)
GeodeticHeight,
/// Geodetic latitude (deg)
GeodeticLatitude,
/// Geodetic longitude (deg)
GeodeticLongitude,
/// Orbital momentum
Hmag,
/// X component of the orbital momentum vector
HX,
/// Y component of the orbital momentum vector
HY,
/// Z component of the orbital momentum vector
HZ,
/// Hyperbolic anomaly (deg), only valid for hyperbolic orbits
HyperbolicAnomaly,
/// Inclination (deg)
Inclination,
/// Mean anomaly (deg)
MeanAnomaly,
/// Periapsis, shortcut for TA == 0.0
Periapsis,
/// Radius of periapse (km)
PeriapsisRadius,
/// Orbital period (s)
Period,
/// Right ascension (deg)
RightAscension,
/// Right ascension of the ascending node (deg)
RAAN,
/// Norm of the radius vector
Rmag,
/// Semi parameter (km)
SemiParameter,
/// Computes the slant angle by returning the arccos of the dot product between state's radius vector and the provided vector coordinates. The vector will be normalized if needed.
SlantAngle { x: f64, y: f64, z: f64 },
/// Semi major axis (km)
SMA,
/// Semi minor axis (km)
SemiMinorAxis,
/// True anomaly
TrueAnomaly,
/// True longitude
TrueLongitude,
/// Velocity declination (deg)
VelocityDeclination,
/// Norm of the velocity vector (km/s)
Vmag,
/// X component of the radius (km)
X,
/// Y component of the radius (km)
Y,
/// Z component of the radius (km)
Z,
/// X component of the velocity (km/s)
VX,
/// Y component of the velocity (km/s)
VY,
/// Z component of the velocity (km/s)
VZ,
/// Allows creating new custom events by matching on the value of the field
Custom { mapping: usize },
}
impl StateParameter {
/// Returns the default event finding precision in the unit of that parameter
pub fn default_event_precision(self) -> f64 {
match self {
Self::Eccentricity => 1e-5,
// Non anomaly angles
Self::AoL
| Self::AoP
| Self::Declination
| Self::GeodeticLatitude
| Self::GeodeticLongitude
| Self::FlightPathAngle
| Self::Inclination
| Self::RightAscension
| Self::RAAN
| Self::TrueLongitude
| Self::VelocityDeclination => 1e-1,
// Anomaly angles
Self::Apoapsis
| Self::Periapsis
| Self::MeanAnomaly
| Self::EccentricAnomaly
| Self::HyperbolicAnomaly
| Self::SlantAngle { .. }
| Self::TrueAnomaly => 1e-3,
// Distances
Self::ApoapsisRadius
| Self::GeodeticHeight
| Self::Hmag
| Self::HX
| Self::HY
| Self::HZ
| Self::PeriapsisRadius
| Self::Rmag
| Self::SemiParameter
| Self::SMA
| Self::SemiMinorAxis
| Self::X
| Self::Y
| Self::Z => 1e-3,
// Velocities
Self::C3 | Self::VX | Self::VY | Self::VZ | Self::Vmag => 1e-3,
// Special
Self::Energy => 1e-3,
Self::FuelMass => 1e-3,
Self::Period => 1e-1,
_ => unimplemented!(),
}
}
/// Returns whether this parameter is of the B-Plane kind
pub fn is_b_plane(self) -> bool {
self == Self::BdotR || self == Self::BdotT || self == Self::BLTOF
}
}
impl FromStr for StateParameter {
type Err = NyxError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let keyword = s.trim().to_lowercase();
match keyword.as_str() {
"apoapsis" => Ok(Self::Apoapsis),
"periapsis" => Ok(Self::Periapsis),
"aol" => Ok(Self::AoL),
"aop" => Ok(Self::AoP),
"c3" => Ok(Self::C3),
"cd" => Ok(Self::Cd),
"cr" => Ok(Self::Cr),
"declin" => Ok(Self::Declination),
"apoapsis_radius" => Ok(Self::ApoapsisRadius),
"ea" => Ok(Self::EccentricAnomaly),
"ecc" => Ok(Self::Eccentricity),
"energy" => Ok(Self::Energy),
"fpa" => Ok(Self::FlightPathAngle),
"fuel_mass" => Ok(Self::FuelMass),
"geodetic_height" => Ok(Self::GeodeticHeight),
"geodetic_latitude" => Ok(Self::GeodeticLatitude),
"geodetic_longitude" => Ok(Self::GeodeticLongitude),
"ha" => Ok(Self::HyperbolicAnomaly),
"hmag" => Ok(Self::Hmag),
"hx" => Ok(Self::HX),
"hy" => Ok(Self::HY),
"hz" => Ok(Self::HZ),
"inc" => Ok(Self::Inclination),
"ma" => Ok(Self::MeanAnomaly),
"periapsis_radius" => Ok(Self::PeriapsisRadius),
"period" => Ok(Self::Period),
"right_asc" => Ok(Self::RightAscension),
"raan" => Ok(Self::RAAN),
"rmag" => Ok(Self::Rmag),
"semi_parameter" => Ok(Self::SemiParameter),
"semi_minor" => Ok(Self::SemiMinorAxis),
"sma" => Ok(Self::SMA),
"ta" => Ok(Self::TrueAnomaly),
"tlong" => Ok(Self::TrueLongitude),
"vdeclin" => Ok(Self::VelocityDeclination),
"vmag" => Ok(Self::Vmag),
"x" => Ok(Self::X),
"y" => Ok(Self::Y),
"z" => Ok(Self::Z),
"vx" => Ok(Self::VX),
"vy" => Ok(Self::VY),
"vz" => Ok(Self::VZ),
_ => Err(NyxError::LoadingError(format!(
"Unknown state parameter: {}",
s
))),
}
}
}