From 3cbeb243ef957d1418a6b25624a26c09433cd729 Mon Sep 17 00:00:00 2001 From: Jay Kickliter Date: Wed, 18 Oct 2023 12:12:56 -0600 Subject: [PATCH] [terrain] propperly take supplied earth radius into account --- propah/src/p2p.rs | 1 + terrain/src/math.rs | 5 ++--- terrain/src/profile.rs | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/propah/src/p2p.rs b/propah/src/p2p.rs index d67675d..533c4d3 100644 --- a/propah/src/p2p.rs +++ b/propah/src/p2p.rs @@ -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. diff --git a/terrain/src/math.rs b/terrain/src/math.rs index 798a028..d68d213 100644 --- a/terrain/src/math.rs +++ b/terrain/src/math.rs @@ -148,11 +148,10 @@ where } /// Returns the up/down angle (in radians) from a to b. -pub fn elevation_angle(start_elev_m: T, distance_m: T, end_elev_m: T) -> T +pub fn elevation_angle(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; @@ -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 ); } diff --git a/terrain/src/profile.rs b/terrain/src/profile.rs index 1adb360..2793437 100644 --- a/terrain/src/profile.rs +++ b/terrain/src/profile.rs @@ -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;