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
extern crate hifitime;
extern crate nalgebra as na;
use self::hifitime::TimeSystem;
use self::hifitime::instant::Instant;
use self::hifitime::julian::ModifiedJulian;
use self::na::Matrix3;
use super::{EARTH, NAIF, SSB};
use std::fmt;
use utils::r3;
pub trait CoordinateFrame: fmt::Display + Copy + fmt::Debug {
type Center: NAIF;
fn to_inertial(at: Instant) -> Matrix3<f64> {
Self::from_inertial(at).transpose()
}
fn from_inertial(at: Instant) -> Matrix3<f64> {
Self::to_inertial(at).transpose()
}
}
#[derive(Copy, Clone, Debug)]
pub struct ICRF {}
impl CoordinateFrame for ICRF {
type Center = SSB;
fn to_inertial(_: Instant) -> Matrix3<f64> {
Matrix3::identity()
}
}
impl fmt::Display for ICRF {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ICRF")
}
}
#[derive(Copy, Clone, Debug)]
pub struct ECI {}
impl CoordinateFrame for ECI {
type Center = EARTH;
fn to_inertial(_: Instant) -> Matrix3<f64> {
Matrix3::identity()
}
}
impl fmt::Display for ECI {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ECI")
}
}
#[derive(Copy, Clone, Debug)]
pub struct ECEF {}
impl ECEF {
pub fn gmst(at: Instant) -> f64 {
use utils::between_0_360;
let t_ut1 = (ModifiedJulian::from_instant(at).julian_days() - 2451545.0) / 36_525.0;
let theta_gmst_secs = (67_310.548_41 + (876_600.0 * 3_600.0 + 8_640_184.812_866) * t_ut1 + 0.093_104 * t_ut1.powi(2)
- 6.2e-6 * t_ut1.powi(3)) % 86_400.0;
between_0_360(theta_gmst_secs / 240.0)
}
pub fn gast(at: Instant) -> f64 {
use std::f64::consts::PI;
let tu = ModifiedJulian::from_instant(at).days - 51_544.5;
2.0 * PI * (0.7790572732640 + 1.00273781191135448 * tu)
}
}
impl CoordinateFrame for ECEF {
type Center = EARTH;
fn from_inertial(at: Instant) -> Matrix3<f64> {
r3(ECEF::gast(at))
}
}
impl fmt::Display for ECEF {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ECEF")
}
}