From aa98d8cebc2bfaba7b60027c1bbb954b74df895a Mon Sep 17 00:00:00 2001 From: yuni Date: Wed, 27 Nov 2024 22:36:43 +0100 Subject: [PATCH] implement nature::jupiter_altitude_to_pressure() --- doc/research.md | 1 + src/nature.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/doc/research.md b/doc/research.md index e4d2469..62c3515 100644 --- a/doc/research.md +++ b/doc/research.md @@ -82,6 +82,7 @@ Based on Figure 27 from SRC1, and Figure 28 using the middle of the 3 temperatur - 350km-850km: `p[bar](a[km]) = e^(-8.0920583983 - 0.0066339143 * a)` - 50km-350km: `p[bar](a[km]) = e^(-0.969198983 - 0.027000953 * a)` - -125km-50km: `p[bar](a[km]) = e^(0.0626589359 - 0.0473755348 * a)` +- <-125km: `p[bar](a[km]) = -715.5577817531 * a - 89044.7227191413` (low-effort linear regression assuming p(-70000km) = 5e7 bar) ### Designing the in-game atmosphere diff --git a/src/nature.rs b/src/nature.rs index a0f1172..843eb0c 100644 --- a/src/nature.rs +++ b/src/nature.rs @@ -271,3 +271,18 @@ pub fn format_seconds_to_hour_min(seconds: f64) -> String { (seconds % 3600.0) / 60.0 ); } + +pub fn jupiter_altitude_to_pressure(altitude: f64) -> f64 { + // See doc/research.md + let a = altitude - JUPITER_RADIUS; + if a >= 1e6 { + return 0.0; + } else if a >= 350e3 { + return (-8.0920583983 - 0.0066339143 * a).exp(); + } else if a >= 50e3 { + return (-0.969198983 - 0.027000953 * a).exp(); + } else if a >= -125e3 { + return (0.0626589359 - 0.0473755348 * a).exp(); + } + return -715.5577817531 * a - 89044.7227191413; +}