Skip to main content

satellite_datetime/
bodies.rs

1//! Generic solar-system bodies: IAU WGCCRE prime-meridian rotation (sidereal).
2//!
3//! Mean solar time on a generic body needs an orbital mean-sun model. Where we
4//! only have `W0`/`Wdot`, we expose **sidereal time at the prime meridian**.
5//! Mars civil time lives in [`crate::mars`]. Do not invent planetary DST.
6
7use crate::instant::Instant;
8
9/// IAU cartographic rotation for a body (Archinal et al. / WGCCRE).
10#[derive(Clone, Copy, Debug)]
11pub struct Body {
12    /// English name.
13    pub name: &'static str,
14    /// Prime meridian at J2000, degrees.
15    pub w0_deg: f64,
16    /// Rotation rate, degrees per day (IAU `d` = days from J2000 TDB ≈ TT).
17    pub wdot_deg_per_day: f64,
18}
19
20/// Mercury (IAU WGCCRE rotation).
21pub const MERCURY: Body = Body {
22    name: "Mercury",
23    w0_deg: 329.5469,
24    wdot_deg_per_day: 6.138_502_5,
25};
26/// Venus (IAU WGCCRE rotation).
27pub const VENUS: Body = Body {
28    name: "Venus",
29    w0_deg: 160.20,
30    wdot_deg_per_day: -1.481_368_8,
31};
32/// Earth (IAU WGCCRE rotation).
33pub const EARTH: Body = Body {
34    name: "Earth",
35    w0_deg: 190.147,
36    wdot_deg_per_day: 360.985_623_5,
37};
38/// Moon (IAU WGCCRE rotation).
39pub const MOON: Body = Body {
40    name: "Moon",
41    w0_deg: 38.3213,
42    wdot_deg_per_day: 13.176_358_15,
43};
44/// Mars (IAU WGCCRE rotation). Sidereal only; civil sols are [`crate::mars`].
45pub const MARS: Body = Body {
46    name: "Mars",
47    w0_deg: 176.630,
48    wdot_deg_per_day: 350.891_982_26,
49};
50/// Jupiter System III (IAU WGCCRE rotation).
51pub const JUPITER: Body = Body {
52    name: "Jupiter",
53    w0_deg: 284.95,
54    wdot_deg_per_day: 870.536_000_0,
55};
56/// Saturn (IAU WGCCRE rotation).
57pub const SATURN: Body = Body {
58    name: "Saturn",
59    w0_deg: 38.90,
60    wdot_deg_per_day: 810.793_902_4,
61};
62/// Uranus (IAU WGCCRE rotation).
63pub const URANUS: Body = Body {
64    name: "Uranus",
65    w0_deg: 203.81,
66    wdot_deg_per_day: -501.160_092_8,
67};
68/// Neptune (IAU WGCCRE rotation).
69pub const NEPTUNE: Body = Body {
70    name: "Neptune",
71    w0_deg: 299.36,
72    wdot_deg_per_day: 541.139_775_7,
73};
74
75/// Mercury through Neptune (and the Moon) as a static table.
76pub const PLANETS: &[Body] = &[
77    MERCURY, VENUS, EARTH, MOON, MARS, JUPITER, SATURN, URANUS, NEPTUNE,
78];
79
80impl Body {
81    /// IAU west-longitude prime meridian angle W in degrees, wrapped to `[0, 360)`.
82    pub fn prime_meridian_deg(self, instant: Instant) -> f64 {
83        let d = instant.julian_tt().as_f64() - crate::J2000_JD;
84        wrap_deg(self.w0_deg + self.wdot_deg_per_day * d)
85    }
86
87    /// Sidereal hour angle of the prime meridian in hours `[0, 24)`.
88    pub fn sidereal_hours(self, instant: Instant) -> f64 {
89        self.prime_meridian_deg(instant) / 15.0
90    }
91}
92
93fn wrap_deg(mut x: f64) -> f64 {
94    x %= 360.0;
95    if x < 0.0 {
96        x += 360.0;
97    }
98    x
99}
100
101#[cfg(test)]
102mod tests {
103    use super::*;
104
105    #[test]
106    fn wrap_and_named_bodies() {
107        assert_eq!(PLANETS.len(), 9);
108        let t = Instant::IAU_1977_TAI;
109        let w = MARS.prime_meridian_deg(t);
110        assert!(w >= 0.0 && w < 360.0);
111        let h = MARS.sidereal_hours(t);
112        assert!(h >= 0.0 && h < 24.0);
113    }
114}