-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06bb10d
commit 76ed1b6
Showing
4 changed files
with
54 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use num_traits::{Float, FloatConst}; | ||
|
||
/// Returns the up/down angle (in radians) from a to b. | ||
pub fn elevation_angle<T>(start_elev_m: T, distance_m: T, end_elev_m: T, earth_radius: T) -> T | ||
where | ||
T: Float + FloatConst, | ||
{ | ||
let a = distance_m; | ||
let b = start_elev_m + earth_radius; | ||
let c = end_elev_m + earth_radius; | ||
let inner = { | ||
let inner = (a.powi(2) + b.powi(2) - c.powi(2)) / ((T::one() + T::one()) * a * b); | ||
if inner < -T::one() { | ||
-T::one() | ||
} else if inner > T::one() { | ||
T::one() | ||
} else { | ||
inner | ||
} | ||
}; | ||
inner.acos() - T::FRAC_PI_2() | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::elevation_angle; | ||
use crate::constants::MEAN_EARTH_RADIUS; | ||
use approx::assert_relative_eq; | ||
|
||
#[test] | ||
fn test_elevation_angle() { | ||
assert_relative_eq!( | ||
0.100_167_342_359_641_42, | ||
elevation_angle(1.0, 1.0, 1.1, MEAN_EARTH_RADIUS), | ||
epsilon = f64::EPSILON | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use num_traits::{Float, FromPrimitive}; | ||
|
||
pub fn linspace<T>(y_start: T, y_end: T, n: usize) -> impl Iterator<Item = T> | ||
where | ||
T: Float + FromPrimitive, | ||
{ | ||
let dy = (y_end - y_start) / T::from(n - 1).unwrap(); | ||
(0..n).map(move |x| y_start + T::from(x).unwrap() * dy) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod elevation_angle; | ||
mod haversine; | ||
mod linspace; | ||
|
||
pub(crate) use {elevation_angle::elevation_angle, haversine::HaversineIter, linspace::linspace}; |