From 74cb35d3acc9f1f5526c1d7cdb77643d2584b496 Mon Sep 17 00:00:00 2001 From: yuni Date: Thu, 28 Nov 2024 01:39:53 +0100 Subject: [PATCH] atmosphere: update pressure regression --- doc/research.md | 10 ++++++---- src/nature.rs | 18 +++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/doc/research.md b/doc/research.md index b16f748..ae85058 100644 --- a/doc/research.md +++ b/doc/research.md @@ -105,10 +105,12 @@ Based on Table 8 from SRC1: ### Regression analysis -- 350km-850km: `p[bar](a[m]) = e^(-8.0920583983 - 0.0000066339143 * a)` -- 50km-350km: `p[bar](a[m]) = e^(-0.969198983 - 0.000027000953 * a)` -- -125km-50km: `p[bar](a[m]) = e^(0.0626589359 - 0.0000473755348 * a)` -- <-125km: `p[bar](a[m]) = -0.7155577817531 * a - 89044.7227191413` (low-effort linear regression assuming p(-70000km) = 5e7 bar) +Pressure: + +- 500km-1029.2km: `p[bar](x[m]) = exp(-13.3961516218 - 0.0000071595 * x)` +- 200km-500km: `p[bar](x[m]) = exp(-3.4340885227 - 0.0000277865 * x)` +- 0km-200km: `p[bar](x[m]) = exp(-0.0020248515 - 0.0000454102 * x)` +- <0km: `p[bar](x[m]) = -(1.45773e-16) * x^3 + 1` (low-effort cubic regression on `[(-70000km, 50Mbar), (0m, 1bar)]`) ### Designing the in-game atmosphere diff --git a/src/nature.rs b/src/nature.rs index 08a99bb..5350d48 100644 --- a/src/nature.rs +++ b/src/nature.rs @@ -289,15 +289,15 @@ pub fn format_seconds_to_hour_min(seconds: f64) -> String { pub fn jupiter_altitude_to_pressure(altitude: f64) -> f64 { // See doc/research.md - let a = altitude - JUPITER_RADIUS; - if a >= 1e6 { + let x = altitude - JUPITER_RADIUS; + if x >= 1030e3 { return 0.0; - } else if a >= 350e3 { - return (-8.0920583983 - 0.0000066339143 * a).exp(); - } else if a >= 50e3 { - return (-0.969198983 - 0.000027000953 * a).exp(); - } else if a >= -125e3 { - return (0.0626589359 - 0.0000473755348 * a).exp(); + } else if x >= 500e3 { + return (-13.3961516218 - 0.0000071595 * x).exp(); + } else if x >= 200e3 { + return (-3.4340885227 - 0.0000277865 * x).exp(); + } else if x >= 0.0 { + return (-0.0020248515 - 0.0000454102 * x).exp(); } - return -0.7155577817531 * a - 89044.7227191413; + return -(1.45773e-16) * x.powf(3.0) + 1; }