Skip to content

Commit

Permalink
Calculate ERA using IAU 2000
Browse files Browse the repository at this point in the history
  • Loading branch information
AngusGMorrison committed Jan 2, 2024
1 parent 8cfdab1 commit 17bd6fe
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/lox_core/src/earth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ mod cio;
mod cip;
mod coordinate_transformations;
mod nutation;
mod rotation_angle;
56 changes: 56 additions & 0 deletions crates/lox_core/src/earth/rotation_angle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2024. Helge Eichhorn and the LOX contributors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*/

//! Module rotation_angle exposes functions for calculating the Earth Rotation Angle (ERA).
use crate::bodies::Earth;
use crate::time::intervals::UT1DaysSinceJ2000;
use crate::types::Radians;
use std::f64::consts::TAU;

impl Earth {
/// Computes the Earth Rotation Angle (ERA) in radians using the IAU 2000 model.
pub fn rotation_angle_00(t: UT1DaysSinceJ2000) -> Radians {
let f = t.rem_euclid(1.0); // fractional part of t
TAU * (f + 0.7790572732640 + 0.00273781191135448 * t) % TAU
}
}

#[cfg(test)]
mod tests {
use super::*;
use float_eq::assert_float_eq;

#[test]
fn test_rotation_angle_00() {
struct TestCase {
t: UT1DaysSinceJ2000,
expected: Radians,
}

[
TestCase {
t: -123.45,
expected: 6.227104062035152,
},
TestCase {
t: 0.0,
expected: 4.894961212823756,
},
TestCase {
t: 123.45,
expected: 3.562818363612361,
},
]
.iter()
.for_each(|tc| {
let actual = Earth::rotation_angle_00(tc.t);
assert_float_eq!(tc.expected, actual, rel <= 1e-9);
});
}
}
2 changes: 2 additions & 0 deletions crates/lox_core/src/time/intervals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub fn tdb_julian_centuries_since_j2000(epoch: Epoch) -> TDBJulianCenturiesSince
}
}

pub type UT1DaysSinceJ2000 = f64;

#[cfg(test)]
mod epoch_tests {
use float_eq::assert_float_eq;
Expand Down

0 comments on commit 17bd6fe

Please sign in to comment.