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
pub const J2000EPOCH: f64 = 2451545.0; pub const J1950EPOCH: f64 = 2433282.5; pub const MJDOFFSET: f64 = 2400000.5; pub struct Epoch { pub juliandate: f64, } impl Epoch { pub fn j2000() -> Self { Self { juliandate: J2000EPOCH, } } pub fn fromjd(jd: f64) -> Self { Self { juliandate: jd } } pub fn frommjd(mjd: f64) -> Self { Self { juliandate: mjd + MJDOFFSET, } } pub fn tomjd(&self) -> f64 { self.juliandate - MJDOFFSET } pub fn centuriessincej2000(&self) -> f64 { (self.juliandate - J2000EPOCH) / 36525.0 } pub fn dayssincej2000(&self) -> f64 { self.juliandate - J2000EPOCH } pub fn gmstdegrees(&self) -> f64 { let t = self.centuriessincej2000(); let gmst = 280.46061837 + 360.98564736629 * self.dayssincej2000() + 0.000387933 * t * t - t * t * t / 38710000.0; let omegarad = (125.04452 - 1934.136261 * t).to_radians(); let lrad = (280.4665 + 36000.7698 * t).to_radians(); let lprad = (218.3165 + 481267.8813 * t).to_radians(); let deltapsiarcsec = -17.20 * omegarad.sin() - 1.32 * (2.0 * lrad).sin() - 0.23 * (2.0 * lprad).sin() + 0.21 * (2.0 * omegarad).sin(); let obliquitydeg = 23.4393 - 0.013 * t; let eqequinox = deltapsiarcsec / 3600.0 * obliquitydeg.to_radians().cos(); (gmst + eqequinox) % 360.0 } pub fn advancedays(&mut self, days: f64) { self.juliandate += days; } pub fn advanceseconds(&mut self, seconds: f64) { self.juliandate += seconds / super::calendar::SECONDSPERDAY; } }