Skip to content

Commit

Permalink
Merge pull request #17 from JayKickliter/jsk/fix-earth-radius
Browse files Browse the repository at this point in the history
[terrain] propperly take supplied earth radius into account
  • Loading branch information
JayKickliter authored Oct 18, 2023
2 parents 403e6dc + 3cbeb24 commit 80ce67e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions propah/src/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ where
.end_alt(self.end_alt_m)
.earth_curve(self.earth_curve)
.normalize(self.normalize)
.earth_radius(self.earth_radius)
.build(tiles)?;

// Unwrap is fine as profiles always have at least two points.
Expand Down
5 changes: 2 additions & 3 deletions terrain/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,10 @@ where
}

/// 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) -> T
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 earth_radius = T::from(MEAN_EARTH_RADIUS).unwrap();
let a = distance_m;
let b = start_elev_m + earth_radius;
let c = end_elev_m + earth_radius;
Expand Down Expand Up @@ -211,7 +210,7 @@ mod tests {
fn test_elevation_angle() {
assert_relative_eq!(
0.100_167_342_359_641_42,
elevation_angle(1.0, 1.0, 1.1),
elevation_angle(1.0, 1.0, 1.1, super::MEAN_EARTH_RADIUS),
epsilon = f64::EPSILON
);
}
Expand Down
5 changes: 3 additions & 2 deletions terrain/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ where
let now = std::time::Instant::now();
if self.earth_curve {
// https://www.trailnotes.org/SizeOfTheEarth/
let earth_radius = C::from(crate::constants::MEAN_EARTH_RADIUS).unwrap();
let earth_radius = self.earth_radius;
let start_elev_alt =
*terrain_elev_m.first().unwrap() + C::from(self.start_alt_m).unwrap();
let start_radius_m = earth_radius + start_elev_alt;
let end_elev_alt =
*terrain_elev_m.last().unwrap() + C::from(self.end_alt_m).unwrap();
let elev_angle_rad = elevation_angle(start_elev_alt, distance_m, end_elev_alt);
let elev_angle_rad =
elevation_angle(start_elev_alt, distance_m, end_elev_alt, self.earth_radius);

let (nb, nm) = if self.normalize {
let nb = -start_elev_alt;
Expand Down

0 comments on commit 80ce67e

Please sign in to comment.