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
pub const J2000_EPOCH: f64 = 2451545.0; pub const J1950_EPOCH: f64 = 2433282.5; pub const MJD_OFFSET: f64 = 2400000.5; pub struct Epoch { pub julian_date: f64, } impl Epoch { pub fn j2000() -> Self { Self { julian_date: J2000_EPOCH, } } pub fn from_jd(jd: f64) -> Self { Self { julian_date: jd } } pub fn from_mjd(mjd: f64) -> Self { Self { julian_date: mjd + MJD_OFFSET, } } pub fn to_mjd(&self) -> f64 { self.julian_date - MJD_OFFSET } pub fn centuries_since_j2000(&self) -> f64 { (self.julian_date - J2000_EPOCH) / 36525.0 } pub fn days_since_j2000(&self) -> f64 { self.julian_date - J2000_EPOCH } pub fn gmst_degrees(&self) -> f64 { let t = self.centuries_since_j2000(); let gmst = 280.460_618_37 + 360.985_647_366_29 * self.days_since_j2000() + 0.000_387_933 * t * t - t * t * t / 38_710_000.0; let omega_rad = (125.04452 - 1934.136261 * t).to_radians(); let l_rad = (280.4665 + 36000.7698 * t).to_radians(); let lp_rad = (218.3165 + 481267.8813 * t).to_radians(); let delta_psi_arcsec = -17.20 * omega_rad.sin() - 1.32 * (2.0 * l_rad).sin() - 0.23 * (2.0 * lp_rad).sin() + 0.21 * (2.0 * omega_rad).sin(); let obliquity_deg = 23.4393 - 0.013 * t; let eq_equinox = delta_psi_arcsec / 3600.0 * obliquity_deg.to_radians().cos(); (gmst + eq_equinox) % 360.0 } pub fn advance_days(&mut self, days: f64) { self.julian_date += days; } pub fn advance_seconds(&mut self, seconds: f64) { self.julian_date += seconds / super::calendar::SECONDS_PER_DAY; } }