Skip to content

Commit 7b403dc

Browse files
Merge pull request #446 from nyx-space/unit_vector
Introduce Unit Vector functions
2 parents eb61d1a + 7f1f43f commit 7b403dc

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

anise/src/almanac/transform.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use hifitime::{Epoch, Unit as TimeUnit};
1212
use snafu::ResultExt;
1313

1414
use crate::{
15-
constants::orientations::J2000,
15+
constants::{
16+
frames::{EARTH_J2000, SUN_J2000},
17+
orientations::J2000,
18+
},
1619
errors::{AlmanacResult, EphemerisSnafu, OrientationSnafu},
1720
math::{cartesian::CartesianState, units::LengthUnit, Vector3},
1821
orientations::OrientationPhysicsSnafu,
@@ -178,4 +181,35 @@ impl Almanac {
178181
action: "transform provided state",
179182
})
180183
}
184+
185+
/// Returns the unitary 3D vector between two [Frame]s (solid bodies) at desired [Epoch]
186+
pub fn unit_vector(
187+
&self,
188+
target_frame: Frame,
189+
observer_frame: Frame,
190+
epoch: Epoch,
191+
ab_corr: Option<Aberration>,
192+
) -> AlmanacResult<Vector3> {
193+
let state = self.transform(target_frame, observer_frame, epoch, ab_corr)?;
194+
Ok(state.radius_km / state.rmag_km())
195+
}
196+
197+
/// Returns the unitary 3D vector between desired [Frame] (solid body) and the Sun at desired [Epoch]
198+
pub fn sun_unit_vector(
199+
&self,
200+
epoch: Epoch,
201+
observer_frame: Frame,
202+
ab_corr: Option<Aberration>,
203+
) -> AlmanacResult<Vector3> {
204+
self.unit_vector(SUN_J2000, observer_frame, epoch, ab_corr)
205+
}
206+
207+
/// Returns the unitary 3D vector between Earth and Sun at desired [Epoch].
208+
pub fn earth_sun_unit_vector(
209+
&self,
210+
epoch: Epoch,
211+
ab_corr: Option<Aberration>,
212+
) -> AlmanacResult<Vector3> {
213+
self.unit_vector(SUN_J2000, EARTH_J2000, epoch, ab_corr)
214+
}
181215
}

0 commit comments

Comments
 (0)