pub fn density_matched_altitude_m(
temperature_c: f64,
station_pressure_hpa: f64,
humidity_percent: f64,
) -> f64Expand description
The altitude in the ICAO Standard Atmosphere whose standard density equals the ACTUAL density of this air, humidity included — density altitude by its textbook definition.
ratio = rho_CIPM(T, P, RH) / rho_CIPM(15 C, 1013.25 hPa, 0%)
h_m = (T0 / L) * (1 - ratio^(1/n)) T0 = 288.15 K, L = 0.0065 K/m,
n = g0 / (R L) - 1 (= 4.25588)§Why this exists alongside faa_rule_density_altitude_ft
Two different quantities are both called “density altitude” in the field, and reporting them under one name is how an external user came to ask why the engine read 0 m where another tool read 36 m at ICAO standard with 50% humidity (2026-09). The FAA-rule figure is humidity-free for compatibility (see its docs). This one answers the question a shooter usually means — “which ISA altitude has the air density I actually have” — and so it must include humidity: water vapor (18 g/mol) is lighter than dry air (~29 g/mol), so humid air is thinner.
At 15 °C, 1013.25 hPa and 50% RH this reads 33.1 m where the FAA-rule figure reads 0. But the difference is NOT purely humidity, and callers must not present it that way: the FAA rule also drifts from this exact figure whenever the temperature is not standard for the pressure altitude, so the two disagree by about 22 m at 30 °C in perfectly dry air.
§Anchoring
Density comes from calculate_atmosphere — the one CIPM-2007 path every solver uses —
and the ratio is taken against that SAME model’s density for ICAO standard dry sea level,
not against the textbook 1.225 kg/m³. The model is accurate, but it is not built to
reproduce 1.225 exactly (its own anchor test allows ±0.002), and at sea level 0.002 kg/m³
is roughly 17 m of altitude. Anchoring to the model makes ICAO standard dry air read
exactly 0 and makes the humidity effect the model’s own.
§Scope
The closed-form troposphere, with no geopotential correction — the same plain-height
convention as the FAA-rule figure and the DA entry mode. That covers every shooting
condition on Earth, but the arithmetic does not know where it stops: above 11 km it keeps
answering, wrongly. Callers bound it; the bridge command refuses conditions outside
-5 km..11 km (crate::atmosphere_service).