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