Engines
BaseIntegrationEngine
¶
BaseIntegrationEngine(config: BaseEngineConfigDict | None)
Bases: ABC, EngineProtocol
All calculations are done in imperial units (feet and fps).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BaseEngineConfigDict | None
|
The configuration object. |
required |
Methods:
| Name | Description |
|---|---|
get_calc_step |
Get step size for integration. |
find_max_range |
Find the maximum range along shot_info.look_angle, and the launch angle to reach it. |
find_apex |
Find the apex of the trajectory. |
find_zero_angle |
Find the barrel elevation needed to hit sight line at a specific distance. |
find_zero_point |
Find a zero trajectory and return its solved angle and terminal point. |
zero_angle |
Find the barrel elevation needed to hit sight line at a specific distance. |
zero_point |
Return the zero angle and the trajectory point used to determine it. |
integrate |
Compute the trajectory for the given shot. |
Source code in py_ballisticcalc/engines/base_engine.py
488 489 490 491 492 493 494 495 | |
get_calc_step
¶
get_calc_step() -> float
Get step size for integration.
Source code in py_ballisticcalc/engines/base_engine.py
497 498 499 | |
find_max_range
¶
find_max_range(
shot_info: Shot,
angle_bracket_deg: tuple[float, float] = (0, 90),
) -> tuple[Distance, Angular]
Find the maximum range along shot_info.look_angle, and the launch angle to reach it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information: gun, ammo, environment, look_angle. |
required |
angle_bracket_deg
|
tuple[float, float]
|
The angle bracket in degrees to search for max range. Defaults to (0, 90). |
(0, 90)
|
Returns:
| Type | Description |
|---|---|
tuple[Distance, Angular]
|
The maximum slant-range and the launch angle to reach it. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the angle bracket excludes the look_angle. |
Source code in py_ballisticcalc/engines/base_engine.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
find_apex
¶
find_apex(shot_info: Shot) -> TrajectoryData
Find the apex of the trajectory.
Apex is defined as the point where the vertical component of velocity goes from positive to negative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TrajectoryData |
TrajectoryData
|
The trajectory data at the apex of the trajectory. |
Raises:
| Type | Description |
|---|---|
SolverRuntimeError
|
If no apex is found in the trajectory data. |
ValueError
|
If barrel elevation is not > 0. |
Source code in py_ballisticcalc/engines/base_engine.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
find_zero_angle
¶
Find the barrel elevation needed to hit sight line at a specific distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
distance
|
Distance
|
Slant distance to the target. |
required |
lofted
|
bool
|
If True, find the higher angle that hits the zero point. |
False
|
Returns:
| Type | Description |
|---|---|
Angular
|
Barrel elevation needed to hit the zero point. |
Source code in py_ballisticcalc/engines/base_engine.py
677 678 679 680 681 682 683 684 685 686 687 688 689 | |
find_zero_point
¶
find_zero_point(
shot_info: Shot,
distance: Distance,
lofted: bool = False,
) -> tuple[Angular, TrajectoryData]
Find a zero trajectory and return its solved angle and terminal point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
distance
|
Distance
|
Slant distance to the target. |
required |
lofted
|
bool
|
If True, find the higher trajectory that hits the zero point. |
False
|
Returns:
| Type | Description |
|---|---|
Angular
|
The solved barrel elevation and the terminal RANGE point from the |
TrajectoryData
|
successful zero-finding iteration. |
Raises:
| Type | Description |
|---|---|
SolverRuntimeError
|
If a zero-angle fast path did not integrate a trajectory and therefore has no trajectory point to return. |
Source code in py_ballisticcalc/engines/base_engine.py
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 | |
zero_angle
¶
Find the barrel elevation needed to hit sight line at a specific distance.
First tries the damped Newton solver; if that fails then falls back on
_find_zero_ridder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
distance
|
Distance
|
The distance to the target. |
required |
Returns:
| Type | Description |
|---|---|
Angular
|
Barrel elevation to hit height zero at zero distance along sight line. |
Source code in py_ballisticcalc/engines/base_engine.py
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 | |
zero_point
¶
zero_point(
shot_info: Shot, distance: Distance
) -> tuple[Angular, TrajectoryData]
Return the zero angle and the trajectory point used to determine it.
This is the terminal RANGE point from the successful zero-finding iteration. It performs no final re-integration after finding the angle, so it is useful to callers that need both the zero geometry and its ballistic state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
distance
|
Distance
|
Slant distance to the zero point. |
required |
Returns:
| Type | Description |
|---|---|
Angular
|
A pair of the lower-arc barrel elevation and the trajectory point |
TrajectoryData
|
from the successful zero-finding iteration. |
Raises:
| Type | Description |
|---|---|
SolverRuntimeError
|
If a zero-angle fast path did not integrate a trajectory and therefore has no trajectory point to return. |
Source code in py_ballisticcalc/engines/base_engine.py
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 | |
integrate
¶
integrate(
shot_info: Shot,
max_range: Distance,
dist_step: Distance | None = None,
time_step: float = 0.0,
filter_flags: TrajFlag | int = NONE,
dense_output: bool = False,
**kwargs,
) -> HitResult
Compute the trajectory for the given shot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
max_range
|
Distance
|
Maximum range of the trajectory (if float then treated as feet). |
required |
dist_step
|
Distance | None
|
Distance step for recording RANGE TrajectoryData rows. |
None
|
time_step
|
float
|
Time step for recording trajectory data. Defaults to 0.0. |
0.0
|
filter_flags
|
TrajFlag | int
|
Flags to filter trajectory data. Defaults to TrajFlag.RANGE. |
NONE
|
dense_output
|
bool
|
If True, HitResult will save BaseTrajData for interpolating TrajectoryData. |
False
|
Returns:
| Type | Description |
|---|---|
HitResult
|
HitResult object for describing the trajectory. |
Source code in py_ballisticcalc/engines/base_engine.py
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 | |
BaseEngineConfigDict
¶
Bases: TypedDict
TypedDict for flexible engine configuration from dictionaries.
This TypedDict provides a flexible way to configure ballistic calculation engines using dictionary syntax. All fields are optional, allowing partial configuration where only specific parameters need to be overridden.
When used with create_base_engine_config(), any unspecified fields will use their default values from DEFAULT_BASE_ENGINE_CONFIG.
Note: All fields are Optional to support partial configuration.
Fields
- cZeroFindingAccuracy: Maximum slant-error in feet for zero-finding precision.
- cMaxIterations: Maximum iterations for convergence algorithms.
- cMinimumAltitude: Minimum altitude in feet to continue calculation.
- cMaximumDrop: Maximum drop in feet from muzzle to continue.
- cMinimumVelocity: Minimum velocity in fps to continue calculation.
- cGravityConstant: Gravitational acceleration in ft/s².
- cStepMultiplier: Integration step size multiplier.
Examples:
>>> config_dict: BaseEngineConfigDict = {
... 'cMinimumVelocity': 100.0,
... 'cStepMultiplier': 0.8
... }
>>> config = create_base_engine_config(config_dict)
>>> # Using with Calculator
>>> from py_ballisticcalc import Calculator
>>> calc = Calculator(config=config_dict)
See Also
- BaseEngineConfig: Type-safe dataclass version
- create_base_engine_config: Factory function for BaseEngineConfig creation
cython+dopri selects
CythonizedDormandPrinceIntegrationEngine when the optional compiled package
is installed. relative_tolerance and absolute_tolerance default to 1e-6;
get_step_stats() returns accepted and rejected steps. Its controller follows
SciPy RK45 semantics, unlike compatibility-preserving Cash--Karp.
cython+tsitouras selects CythonizedTsitourasIntegrationEngine the
same way. It is structurally identical to CythonizedDormandPrinceIntegrationEngine
(same 7-stage FSAL shape, same SciPy-RK45-style controller, same relative_tolerance/
absolute_tolerance config) but uses the Tsitouras 5(4) tableau instead of
Dormand-Prince's — measured to be in the same performance class as Dormand-Prince and
Cash--Karp, not consistently faster, despite its smaller leading truncation-error
coefficient; see benchmarks.
RK4IntegrationEngine
¶
RK4IntegrationEngine(config: BaseEngineConfigDict | None)
Bases: BaseIntegrationEngine
Runge-Kutta 4th order integration engine for ballistic trajectory calculations.
Attributes:
| Name | Type | Description |
|---|---|---|
integration_step_count |
int
|
Number of integration steps performed. |
Examples:
>>> config = BaseEngineConfigDict(cMinimumVelocity=0.0)
>>> engine = RK4IntegrationEngine(config)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BaseEngineConfigDict | None
|
Configuration dictionary containing engine parameters.
See |
required |
Examples:
>>> precise_config = BaseEngineConfigDict(
... cStepMultiplier=0.5, # Smaller steps
... cMinimumVelocity=20.0 # Continue to lower velocities
... )
>>> precise_engine = RK4IntegrationEngine(precise_config)
Methods:
| Name | Description |
|---|---|
get_calc_step |
Get the calculation step size for RK4 integration. |
Source code in py_ballisticcalc/engines/rk4.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
get_calc_step
¶
get_calc_step() -> float
Get the calculation step size for RK4 integration.
Returns:
| Type | Description |
|---|---|
float
|
Time-step size (in seconds) for integration calculations. |
Mathematical Context
The step size directly affects the accuracy and computational cost: - Smaller steps: Higher accuracy, more computation - Larger steps: Lower accuracy, faster computation - RK4's O(h⁵) error means accuracy improves rapidly with smaller h
Examples:
>>> config = BaseEngineConfigDict(cStepMultiplier=0.5)
>>> engine = RK4IntegrationEngine(config)
>>> engine.get_calc_step()
0.00125
Note
For RK4, the relationship between step size and accuracy is: - Halving the step size reduces error by ~32× (2⁵) - Default step size is sufficient to pass unit tests.
Source code in py_ballisticcalc/engines/rk4.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
EulerIntegrationEngine
¶
EulerIntegrationEngine(config: BaseEngineConfigDict | None)
Bases: BaseIntegrationEngine
Euler integration engine for ballistic trajectory calculations.
Attributes:
| Name | Type | Description |
|---|---|---|
DEFAULT_STEP |
Default step size multiplier for integration (0.5). |
|
integration_step_count |
int
|
Number of integration steps performed. |
Examples:
>>> config = BaseEngineConfigDict(cMinimumVelocity=100.0)
>>> engine = EulerIntegrationEngine(config)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BaseEngineConfigDict | None
|
Configuration dictionary containing engine parameters.
See [ |
required |
Methods:
| Name | Description |
|---|---|
get_calc_step |
Get the base calculation step size for Euler integration. |
time_step |
Calculate adaptive time step based on current projectile velocity. |
Source code in py_ballisticcalc/engines/euler.py
66 67 68 69 70 71 72 73 74 75 | |
get_calc_step
¶
get_calc_step() -> float
Get the base calculation step size for Euler integration.
Calculates the effective step size by combining the base engine step multiplier with the Euler-specific DEFAULT_STEP constant. The step size directly affects accuracy and performance trade-offs. This is a distance-like quantity that is subsequently scaled by velocity to produce a time-like integration step.
Returns:
| Type | Description |
|---|---|
float
|
Base step size for integration calculations. |
Note
The step size is calculated as: cStepMultiplier * DEFAULT_STEP.
Smaller step sizes increase accuracy but require more computation.
The DEFAULT_STEP is sufficient to pass all unit tests.
Source code in py_ballisticcalc/engines/euler.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
time_step
¶
Calculate adaptive time step based on current projectile velocity.
Implements adaptive time stepping where the time step is inversely related to projectile velocity. This helps maintain numerical stability and accuracy as the projectile slows down or speeds up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_step
|
float
|
Base step size from the integration engine. |
required |
velocity
|
float
|
Current projectile velocity in fps. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Adaptive time step for the current integration step. |
Formula
time_step = base_step / max(1.0, velocity)
Examples:
>>> config = BaseEngineConfigDict(cStepMultiplier=0.5)
>>> engine = EulerIntegrationEngine(config)
>>> engine.time_step(0.5, 2000.0)
0.00025
>>> engine.time_step(0.5, 100.0)
0.005
Note
The max(1.0, velocity) ensures that the time step never becomes excessively large, maintaining numerical stability even at very low velocities.
Source code in py_ballisticcalc/engines/euler.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
VelocityVerletIntegrationEngine
¶
VelocityVerletIntegrationEngine(
config: BaseEngineConfigDict | None,
)
Bases: BaseIntegrationEngine
Velocity Verlet integration engine for ballistic trajectory calculations.
Algorithm Details
The method uses a two-stage approach: 1. Update position using current velocity and acceleration. 2. Update velocity using average of current and new acceleration. This ensures velocity and position remain properly synchronized and conserves the total energy of the system.
Attributes:
| Name | Type | Description |
|---|---|---|
DEFAULT_TIME_STEP |
Default time step multiplier. |
|
integration_step_count |
int
|
Number of integration steps performed. |
See Also
- RK4IntegrationEngine: Higher accuracy alternative
- EulerIntegrationEngine: Simpler alternative
- SciPyIntegrationEngine: Adaptive methods
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BaseEngineConfigDict | None
|
Configuration dictionary containing engine parameters.
See |
required |
Examples:
>>> config = BaseEngineConfigDict(
... cStepMultiplier=0.5,
... cMinimumVelocity=10.0
... )
>>> engine = VelocityVerletIntegrationEngine(config)
Methods:
| Name | Description |
|---|---|
get_calc_step |
Get the calculation step size for Velocity Verlet integration. |
Source code in py_ballisticcalc/engines/velocity_verlet.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
get_calc_step
¶
get_calc_step() -> float
Get the calculation step size for Velocity Verlet integration.
Combines the base engine step multiplier with the Verlet-specific DEFAULT_TIME_STEP to determine the effective integration step size.
Returns:
| Type | Description |
|---|---|
float
|
Effective step size for Velocity Verlet integration. |
Formula
step_size = base_step_multiplier × DEFAULT_TIME_STEP
Note
The small DEFAULT_TIME_STEP value is chosen to ensure that this engine can pass all unit tests, despite most of them being highly dissipative rather than conservative of energy.
Source code in py_ballisticcalc/engines/velocity_verlet.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
SciPyIntegrationEngine
¶
SciPyIntegrationEngine(
config: SciPyEngineConfigDict | None,
)
Bases: BaseIntegrationEngine
High-performance ballistic trajectory integration engine using SciPy's solve_ivp.
Examples:
>>> from py_ballisticcalc.engines.scipy_engine import SciPyIntegrationEngine, SciPyEngineConfigDict
>>>
>>> # High-precision configuration
>>> config = SciPyEngineConfigDict(
... integration_method='DOP853',
... relative_tolerance=1e-10,
... absolute_tolerance=1e-12
... )
>>> engine = SciPyIntegrationEngine(config)
>>>
>>> # Using with Calculator
>>> from py_ballisticcalc import Calculator
>>> calc = Calculator(engine='scipy+dop853')
Note
Requires scipy and numpy packages. Install with:
pip install py_ballisticcalc[scipy] or pip install scipy numpy
Sets up the engine with the provided configuration dictionary, initializing all necessary parameters for high-precision ballistic trajectory calculations. The configuration is converted to a structured format with appropriate defaults for any unspecified parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_config
|
Configuration dictionary containing engine parameters.
Can include SciPy-specific options (integration_method,
tolerances, max_time) as well as all standard |
required |
Raises:
| Type | Description |
|---|---|
ImportError
|
If scipy or numpy packages are not available. |
ValueError
|
If configuration contains invalid parameters. |
Examples:
>>> config = SciPyEngineConfigDict(
... integration_method='DOP853',
... relative_tolerance=1e-10,
... cMinimumVelocity=50.0
... )
>>> engine = SciPyIntegrationEngine(config)
Attributes Initialized
- _config: Complete configuration with defaults applied
- gravity_vector: Gravitational acceleration vector
- integration_step_count: Counter for integration steps (debugging)
- trajectory_count: Counter for calculated trajectories (debugging)
- eval_points: list of evaluation points (debugging/analysis)
Note
The configuration is processed through create_scipy_engine_config() which applies defaults for any unspecified parameters. This ensures the engine always has a complete, valid configuration.
Methods:
| Name | Description |
|---|---|
find_zero_angle |
Find a zero angle with SciPy's |
find_zero_point |
Find a zero point with SciPy's |
zero_angle |
Find the lower zero angle, falling back from Newton to |
zero_point |
Return SciPy's zero solution and its already-evaluated terminal point. |
Source code in py_ballisticcalc/engines/scipy_engine.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
find_zero_angle
¶
Find a zero angle with SciPy's brentq root solver.
Source code in py_ballisticcalc/engines/scipy_engine.py
819 820 821 822 823 | |
find_zero_point
¶
find_zero_point(
shot_info: Shot,
distance: Distance,
lofted: bool = False,
) -> tuple[Angular, TrajectoryData]
Find a zero point with SciPy's brentq root solver.
Source code in py_ballisticcalc/engines/scipy_engine.py
825 826 827 828 829 830 831 832 833 834 | |
zero_angle
¶
Find the lower zero angle, falling back from Newton to brentq.
Source code in py_ballisticcalc/engines/scipy_engine.py
836 837 838 839 840 841 842 843 844 | |
zero_point
¶
zero_point(
shot_info: Shot, distance: Distance
) -> tuple[Angular, TrajectoryData]
Return SciPy's zero solution and its already-evaluated terminal point.
Unlike the base implementation, this directly uses the root_scalar
solver implemented by :meth:_find_zero_brentq.
Source code in py_ballisticcalc/engines/scipy_engine.py
846 847 848 849 850 851 852 853 854 855 856 857 | |
SciPyEngineConfigDict
¶
Bases: BaseEngineConfigDict
TypedDict for flexible SciPy integration engine configuration.
This TypedDict provides a flexible dictionary-based interface for configuring the SciPy integration engine. All fields are optional (total=False), allowing partial configuration with automatic fallback to default values.
Attributes:
| Name | Type | Description |
|---|---|---|
max_time |
float
|
Maximum simulation time in seconds before terminating integration. Prevents runaway calculations in edge cases. If not specified, uses DEFAULT_MAX_TIME (90.0 seconds). |
relative_tolerance |
float
|
Relative tolerance for integration error control (rtol). Controls the relative accuracy of the numerical solution. Smaller values provide higher precision at computational cost. If not specified, uses DEFAULT_RELATIVE_TOLERANCE (1e-8). |
absolute_tolerance |
float
|
Absolute tolerance for integration error control (atol). Controls absolute accuracy, particularly important near zero. Smaller values improve precision for small quantities. If not specified, uses DEFAULT_ABSOLUTE_TOLERANCE (1e-6). |
integration_method |
INTEGRATION_METHOD
|
SciPy solve_ivp integration method selection. If not specified, uses DEFAULT_INTEGRATION_METHOD ('RK45'). |
Examples:
>>> # Minimal configuration - uses defaults for unspecified fields
>>> config: SciPyEngineConfigDict = {
... 'integration_method': 'DOP853' # High precision
... }
SciPyIntegrationEngineFactory
¶
SciPyIntegrationEngineFactory(
method: INTEGRATION_METHOD,
) -> Callable[
[SciPyEngineConfigDict | None], SciPyIntegrationEngine
]
Make an engine factory with the SciPy solve_ivp integration method preset.
The returned callable matches EngineFactoryProtocol; integration_method from the
passed config is overridden by method.
Examples:
>>> calc = Calculator(engine=SciPyIntegrationEngineFactory("DOP853"))
Source code in py_ballisticcalc/engines/scipy_engine.py
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
CythonizedBaseIntegrationEngine
¶
CythonizedBaseIntegrationEngine(
config: BaseEngineConfigDict | None,
)
Bases: EngineProtocol
Base Cython wrapper for C/С++ based binary engine. Implements EngineProtocol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BaseEngineConfig
|
The engine configuration. |
required |
IMPORTANT
Avoid calling Python functions inside __init__!
__init__ is called after __cinit__, so any memory allocated in __cinit__
that is not referenced in Python will be leaked if __init__ raises an exception.
Methods:
| Name | Description |
|---|---|
find_max_range |
Finds the maximum range along shot_info.look_angle, |
find_zero_angle |
Finds the barrel elevation needed to hit sight line at a specific distance, |
find_zero_point |
Find a zero trajectory and return its solved angle and terminal point. |
find_apex |
Finds the apex of the trajectory, where apex is defined as the point |
zero_angle |
Finds the barrel elevation needed to hit sight line at a specific distance. |
zero_point |
Return the zero angle and the trajectory point used to determine it. |
integrate |
Integrates the trajectory for the given shot. |
integrate_raw_at |
Integrates the trajectory until a specified attribute reaches a target value |
Attributes:
| Name | Type | Description |
|---|---|---|
integration_step_count |
int
|
Gets the number of integration steps performed in the last integration. |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
29 30 31 32 33 34 35 36 37 38 39 40 | |
integration_step_count
property
¶
integration_step_count: int
Gets the number of integration steps performed in the last integration.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of integration steps. |
find_max_range
¶
find_max_range(
shot_info: Shot,
angle_bracket_deg: tuple[float, float] = (0, 90),
) -> tuple[Distance, Angular]
Finds the maximum range along shot_info.look_angle, and the launch angle to reach it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
angle_bracket_deg
|
tuple[float, float]
|
The angle bracket in degrees to search for max range. Defaults to (0, 90). |
(0, 90)
|
Returns:
| Type | Description |
|---|---|
tuple[Distance, Angular]
|
tuple[Distance, Angular]: The maximum slant range and the launch angle to reach it. |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
find_zero_angle
¶
Finds the barrel elevation needed to hit sight line at a specific distance, using unimodal root-finding that is guaranteed to succeed if a solution exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
distance
|
Distance
|
The distance to the target. |
required |
lofted
|
bool
|
Whether the shot is lofted. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Angular |
Angular
|
The required barrel elevation angle. |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
84 85 86 87 88 89 90 91 92 93 94 95 96 | |
find_zero_point
¶
find_zero_point(
shot_info: Shot,
distance: Distance,
lofted: bool = False,
) -> tuple[Angular, TrajectoryData]
Find a zero trajectory and return its solved angle and terminal point.
The returned point is the terminal RANGE point evaluated by the
successful zero-finding iteration. No final trajectory integration is
performed after the angle is found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
distance
|
Distance
|
Slant distance to the target. |
required |
lofted
|
bool
|
If True, find the higher trajectory that hits the zero point. |
False
|
Returns:
| Type | Description |
|---|---|
Angular
|
The solved barrel elevation and the terminal RANGE point from the |
TrajectoryData
|
successful zero-finding iteration. |
Raises:
| Type | Description |
|---|---|
SolverRuntimeError
|
If a zero-angle fast path did not integrate a trajectory and therefore has no trajectory point to return. |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
find_apex
¶
find_apex(shot_info: Shot) -> TrajectoryData
Finds the apex of the trajectory, where apex is defined as the point where the vertical component of velocity goes from positive to negative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TrajectoryData |
TrajectoryData
|
The trajectory data at the apex. |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
121 122 123 124 125 126 127 128 129 130 131 | |
zero_angle
¶
Finds the barrel elevation needed to hit sight line at a specific distance. First tries iterative approach; if that fails falls back on _find_zero_angle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
distance
|
Distance
|
The distance to the target. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Angular |
Angular
|
Barrel elevation to hit height zero at zero distance along sight line |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
133 134 135 136 137 138 139 140 141 142 143 144 | |
zero_point
¶
zero_point(
shot_info: Shot, distance: Distance
) -> tuple[Angular, TrajectoryData]
Return the zero angle and the trajectory point used to determine it.
This is the terminal RANGE point from the successful zero-finding
iteration. It performs no final re-integration after finding the
angle, so callers receive both the zero geometry and its ballistic
state from one solve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
distance
|
Distance
|
Slant distance to the zero point. |
required |
Returns:
| Type | Description |
|---|---|
Angular
|
A pair of the lower-arc barrel elevation and the trajectory point |
TrajectoryData
|
from the successful zero-finding iteration. |
Raises:
| Type | Description |
|---|---|
SolverRuntimeError
|
If a zero-angle fast path did not integrate a trajectory and therefore has no trajectory point to return. |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
integrate
¶
integrate(
shot_info: Shot,
max_range: Distance,
dist_step: Distance | None = None,
time_step: float = 0.0,
filter_flags: TrajFlag | int = 0,
dense_output: bool = False,
**kwargs: Any,
) -> HitResult
Integrates the trajectory for the given shot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
Shot
|
The shot information. |
required |
max_range
|
Distance
|
Maximum range of the trajectory (if float then treated as feet). |
required |
dist_step
|
Distance | None
|
Distance step for recording RANGE TrajectoryData rows. |
None
|
time_step
|
float
|
Time step for recording trajectory data. Defaults to 0.0. |
0.0
|
filter_flags
|
TrajFlag | int
|
Flags to filter trajectory data. Defaults to TrajFlag.RANGE. |
0
|
dense_output
|
bool
|
If True, HitResult will save BaseTrajData for interpolating TrajectoryData. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
HitResult |
HitResult
|
Object for describing the trajectory. |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
integrate_raw_at
¶
integrate_raw_at(
shot_info: Shot, key_attribute: str, target_value: float
) -> tuple[CythonizedBaseTrajData, TrajectoryData]
Integrates the trajectory until a specified attribute reaches a target value and returns the interpolated data point.
This method initializes the trajectory using the provided shot information, performs integration using the underlying C++ engine's 'integrate_at' function, and handles the conversion of C++ results back to Python objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shot_info
|
object
|
Information required to initialize the trajectory (e.g., muzzle velocity, drag model). |
required |
key_attribute
|
str
|
The name of the attribute to track, such as 'time', 'mach', or a vector component like 'position.z'. |
required |
target_value
|
float
|
The value the 'key_attribute' must reach for the integration to stop and interpolation to occur. |
required |
Returns:
| Type | Description |
|---|---|
tuple[CythonizedBaseTrajData, TrajectoryData]
|
tuple[CythonizedBaseTrajData, TrajectoryData]: A tuple containing: - CythonizedBaseTrajData: The interpolated raw data point. - TrajectoryData: The fully processed trajectory data point. |
Raises:
| Type | Description |
|---|---|
InterceptionError
|
If the underlying C++ integration fails to find the target point (e.g., due to insufficient range or data issues). |
SolverRuntimeError
|
If some other internal error occured |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
CythonizedRK4IntegrationEngine
¶
CythonizedRK4IntegrationEngine(
config: BaseEngineConfigDict | None,
)
Bases: CythonizedBaseIntegrationEngine[BaseEngineConfigDict]
Cythonized RK4 (Runge-Kutta 4th order) integration engine for ballistic calculations.
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
29 30 31 32 33 34 35 36 37 38 39 40 | |
CythonizedEulerIntegrationEngine
¶
CythonizedEulerIntegrationEngine(
config: BaseEngineConfigDict | None,
)
Bases: CythonizedBaseIntegrationEngine[BaseEngineConfigDict]
Cythonized Euler integration engine for ballistic calculations.
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
29 30 31 32 33 34 35 36 37 38 39 40 | |
CythonizedVelocityVerletIntegrationEngine
¶
CythonizedVelocityVerletIntegrationEngine(
config: BaseEngineConfigDict | None,
)
Bases: CythonizedBaseIntegrationEngine[BaseEngineConfigDict]
Cythonized Velocity Verlet integration engine for ballistic calculations.
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/base_engine.pyi
29 30 31 32 33 34 35 36 37 38 39 40 | |
CythonizedCashKarpIntegrationEngine
¶
CythonizedCashKarpIntegrationEngine(
config: CashKarpEngineConfig
| BaseEngineConfigDict
| None = None,
)
Bases: CythonizedBaseIntegrationEngine[BaseEngineConfigDict]
Cythonized Cash-Karp (embedded adaptive RK45) integration engine for ballistic calculations.
The scalar relative_tolerance and absolute_tolerance config keys
control the embedded local-error estimate with solve_ivp semantics.
Both default to 1e-6.
Methods:
| Name | Description |
|---|---|
get_step_stats |
Returns (accepted, rejected) step counts from the most recent integration call. |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/engines.pyi
76 77 | |
get_step_stats
¶
Returns (accepted, rejected) step counts from the most recent integration call.
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/engines.pyi
79 80 | |
CythonizedDormandPrinceIntegrationEngine
¶
CythonizedDormandPrinceIntegrationEngine(
config: DormandPrinceEngineConfig
| BaseEngineConfigDict
| None = None,
)
Bases: CythonizedBaseIntegrationEngine[BaseEngineConfigDict]
Cythonized Dormand-Prince 5(4) integration engine with solve_ivp-style tolerances.
Methods:
| Name | Description |
|---|---|
get_step_stats |
Returns (accepted, rejected) step counts from the most recent integration call. |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/engines.pyi
101 | |
get_step_stats
¶
Returns (accepted, rejected) step counts from the most recent integration call.
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/engines.pyi
102 103 | |
CythonizedTsitourasIntegrationEngine
¶
CythonizedTsitourasIntegrationEngine(
config: TsitourasEngineConfig
| BaseEngineConfigDict
| None = None,
)
Bases: CythonizedBaseIntegrationEngine[BaseEngineConfigDict]
Cythonized Tsitouras 5(4) integration engine with solve_ivp-style tolerances.
Methods:
| Name | Description |
|---|---|
get_step_stats |
Returns (accepted, rejected) step counts from the most recent integration call. |
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/engines.pyi
124 | |
get_step_stats
¶
Returns (accepted, rejected) step counts from the most recent integration call.
Source code in py_ballisticcalc.exts/py_ballisticcalc_exts/engines.pyi
125 126 | |