Architecture Overview¶
Goals
- Keep a compact, well-tested ballistic calculator.
- Provide multiple integration engines (pure-Python and Cython-accelerated engines).
- Expose consistent APIs and event semantics (zero crossings, Mach crossing, apex) across engines.
High-level layers¶
1. Public API¶
Calculatoris the top-level interface used by most clients.
2. Scene / shot description¶
- py_ballisticcalc.shot.Shot captures the shot parameters:
ammo,weapon,look_angle,relative_angle,windand atmosphere. - Ammo, Weapon, and Atmo live in
py_ballisticcalc.munition.pyandpy_ballisticcalc.conditions.py.
3. Drag model¶
- py_ballisticcalc.drag_model and py_ballisticcalc.drag_tables provide the drag lookup and interpolation used by the integrators.
4. Integration engines¶
- Engines implement EngineProtocol (see
py_ballisticcalc.generics.engine). - Cython engines are compiled in
py_ballisticcalc.exts/py_ballisticcalc_extsfor performance. Seerk4_engine.pyxandeuler_engine.pyximplementations.
5. Trajectory data and events¶
py_ballisticcalc.trajectory_data.pydefinesTrajFlag,BaseTrajData,TrajectoryData, andHitResult.TrajFlagevent flags include:ZERO_UP,ZERO_DOWN,MACH,RANGE,APEX, and they are recorded with union semantics when they occur within a small time window.- py_ballisticcalc.engines.base_engine.TrajectoryDataFilter:
- Converts raw step samples to recorded
TrajectoryDatarows. - Handles sampling by range/time.
- Detects
TrajFlagevents and performs interpolation for precise event timestamps/values. - Applies unioning of flags within
BaseIntegrationEngine.SEPARATE_ROW_TIME_DELTA.
- Converts raw step samples to recorded
6. Search helpers¶
- The engine provides root-finding and search helpers implemented on top of the
integrate()method:zero_angle, which falls back on the more computationally demanding but reliablefind_zero_angle, findsbarrel_elevationto hit a sight distance.find_max_rangefinds angle that maximizes slant range.find_apexfinds the apex, which is where vertical velocity crosses from positive to negative.
- To ensure parity between engines, these searches run the same Python-side logic and temporarily relax termination constraints where needed.
Integration details & parity¶
- Cython engines return dense BaseTrajData samples; Python py_ballisticcalc.engines.base_engine.TrajectoryDataFilter is responsible for event interpolation. This design keeps the high-level semantics in one place and reduces duplication.