ballistics_engine/constants.rs
1/// Physical constants used in ballistics calculations
2
3/// Gravitational acceleration in m/s²
4pub const G_ACCEL_MPS2: f64 = 9.80665;
5
6/// Conversion factor: meters per second to feet per second
7pub const MPS_TO_FPS: f64 = 3.28084;
8
9/// Conversion factor: feet per second to meters per second
10pub const FPS_TO_MPS: f64 = 0.3048;
11
12/// Default powder reference temperature in Fahrenheit.
13pub const DEFAULT_POWDER_REFERENCE_TEMP_F: f64 = 70.0;
14
15/// Default powder reference temperature in Celsius.
16pub const DEFAULT_POWDER_REFERENCE_TEMP_C: f64 =
17 (DEFAULT_POWDER_REFERENCE_TEMP_F - 32.0) * 5.0 / 9.0;
18
19/// Standard air density at sea level (kg/m³)
20pub const STANDARD_AIR_DENSITY: f64 = 1.225;
21
22/// Cd-to-retardation conversion for ICAO-referenced BCs.
23///
24/// Exact imperial retardation form for density normalized to ICAO sea-level air
25/// (1.225 kg/m^3 / 0.076474 lb/ft^3):
26///
27/// `a_ft/s^2 = Cd * v_fps^2 * (rho / 1.225) * CD_TO_RETARD / BC`
28///
29/// The older `0.000683 * 0.30` value is the Army Standard Metro constant and is
30/// only consistent with a 0.075126 lb/ft^3 density reference.
31pub const CD_TO_RETARD: f64 = 2.08551e-4;
32
33/// Conversion factor: grains to kilograms
34pub const GRAINS_TO_KG: f64 = 0.00006479891;
35
36/// Air density at sea level (kg/m³)
37pub const AIR_DENSITY_SEA_LEVEL: f64 = 1.225;
38
39/// Speed of sound at sea level, standard atmospheric conditions
40///
41/// Value: 340.29 m/s (1116.44 ft/s)
42/// Conditions: 15°C (59°F), 1013.25 hPa, dry air
43///
44/// Temperature dependence: c = 331.3 * sqrt(T_kelvin / 273.15)
45///
46/// Note: Some calculations use 343.0 m/s (20°C reference) - ensure consistency
47/// in Mach number calculations. This value follows ICAO Standard Atmosphere.
48///
49/// Source: International Standard Atmosphere (ISO 2533)
50pub const SPEED_OF_SOUND_MPS: f64 = 340.29;
51
52// Numerical stability constants
53/// General numerical tolerance for floating point comparisons
54pub const NUMERICAL_TOLERANCE: f64 = 1e-9;
55
56/// Minimum threshold for velocity magnitude to avoid division by zero
57pub const MIN_VELOCITY_THRESHOLD: f64 = 1e-6;
58
59/// Minimum threshold for preventing division by zero in general calculations
60pub const MIN_DIVISION_THRESHOLD: f64 = 1e-12;
61
62/// Tolerance for root finding algorithms
63pub const ROOT_FINDING_TOLERANCE: f64 = 1e-6;
64
65/// Minimum threshold for Mach number calculations near unity
66pub const MIN_MACH_THRESHOLD: f64 = 1e-3;
67
68// Ballistic Coefficient (BC) fallback constants
69//
70// These values are used when BC calculations fail or data is missing.
71// Derived from statistical analysis of 2,000+ projectile database.
72// Values represent conservative estimates (25th percentile) to avoid
73// over-predicting ballistic performance.
74
75/// Conservative overall BC fallback value
76///
77/// Value: 0.31 (25th percentile from comprehensive ballistics database)
78/// Usage: General fallback when no specific projectile data available
79/// Methodology: Statistical analysis of measured BC values across all categories
80pub const BC_FALLBACK_CONSERVATIVE: f64 = 0.31;
81
82/// BC fallback values by projectile weight category (grains)
83///
84/// Values based on statistical analysis of ballistic coefficient vs mass relationships.
85/// Each constant represents 25th percentile BC for that weight category.
86
87/// Ultra-light projectiles (0-50 grains)
88/// Typical: .17 caliber varmint bullets, .22 caliber target bullets
89pub const BC_FALLBACK_ULTRA_LIGHT: f64 = 0.172;
90
91/// Light projectiles (50-100 grains)
92/// Typical: .223 Remington, .243 Winchester hunting bullets
93pub const BC_FALLBACK_LIGHT: f64 = 0.242;
94
95/// Medium projectiles (100-150 grains)
96/// Typical: .270 Winchester, .30-06 hunting bullets
97pub const BC_FALLBACK_MEDIUM: f64 = 0.310;
98
99/// Heavy projectiles (150-200 grains)
100/// Typical: .308 Winchester match bullets, .300 Winchester Magnum
101pub const BC_FALLBACK_HEAVY: f64 = 0.393;
102
103/// Very heavy projectiles (200+ grains)
104/// Typical: .338 Lapua Magnum, .50 BMG bullets
105pub const BC_FALLBACK_VERY_HEAVY: f64 = 0.441;
106
107/// BC fallback values by caliber category (inches)
108///
109/// Values account for diameter limitations on achievable ballistic coefficient.
110/// Larger calibers generally allow higher BC but with diminishing returns.
111
112/// Small calibers (.224" and smaller)
113/// Examples: .17 Remington, .22-250, .223 Remington
114pub const BC_FALLBACK_SMALL_CALIBER: f64 = 0.215;
115
116/// Medium calibers (.243")
117/// Examples: .243 Winchester, 6mm Creedmoor
118pub const BC_FALLBACK_MEDIUM_CALIBER: f64 = 0.300;
119
120/// Large calibers (.264" to .284")
121/// Examples: .270 Winchester, .280 Remington, 7mm Remington Magnum
122pub const BC_FALLBACK_LARGE_CALIBER: f64 = 0.404;
123
124/// Extra large calibers (.308" and larger)
125/// Examples: .308 Winchester, .30-06, .300 Winchester Magnum
126/// Note: Lower than expected due to inclusion of older, less aerodynamic designs
127pub const BC_FALLBACK_XLARGE_CALIBER: f64 = 0.291;
128
129#[cfg(test)]
130mod tests {
131 use super::*;
132
133 #[test]
134 fn powder_reference_temperature_defaults_are_equivalent() {
135 let converted = (DEFAULT_POWDER_REFERENCE_TEMP_F - 32.0) * 5.0 / 9.0;
136
137 assert_eq!(
138 DEFAULT_POWDER_REFERENCE_TEMP_C.to_bits(),
139 converted.to_bits()
140 );
141 }
142}