LGPL library for small arms ballistic calculations based on point-mass (3 DoF) plus spin drift.
pip install py-ballisticcalc
# Using precompiled backend (improves performance)
pip install "py-ballisticcalc[exts]"
# Using matplotlib and pandas uses additional dependencies
pip install "py-ballisticcalc[charts]"
# Get everything, including the SciPy engine
pip install "pyballistic[exts,charts,scipy]"
Work in your preferred terms with easy conversions for the following dimensions and units:
- Angular: radian, degree, MOA, mil, mrad, thousandth, inch/100yd, cm/100m, o'clock
- Distance: inch, foot, yard, mile, nautical mile, mm, cm, m, km, line
- Energy: foot-pound, joule
- Pressure: mmHg, inHg, bar, hPa, PSI
- Temperature: Fahrenheit, Celsius, Kelvin, Rankine
- Time: second, minute, millisecond, microsecond, nanosecond, picosecond
- Velocity: m/s, km/h, ft/s, mph, knots
- Weight: grain, ounce, gram, pound, kilogram, newton
Choose between different calculation engines, or build your own. Included engines:
Engine Name | Speed | Dependencies | Description |
---|---|---|---|
rk4_engine |
Baseline (1x) | None, default | Runge-Kutta 4th-order integration |
euler_engine |
0.5x (slower) | None | Euler 1st-order integration |
verlet_engine |
0.7x (slower) | None | Verlet 2nd-order integration |
cythonized_rk4_engine |
50x (faster) | [exts] |
Compiled Runge-Kutta 4th-order |
cythonized_euler_engine |
40x (faster) | [exts] |
Compiled Euler integration |
scipy_engine |
10x (faster) | scipy |
Advanced numerical methods |
The library provides trajectory calculation for ballistic projectiles launched by airguns, bows, firearms, artillery, etc.
The core point-mass (3DoF) ballistic model underlying this project was used on the earliest digital computers. Robert McCoy (author of Modern Exterior Ballistics) implemented one in BASIC. JBM published code in C. Nikolay Gekht ported that to C#, extended it with formulas from Bryan Litz's Applied Ballistics, and ported it to Go, while Alexandre Trofimov implemented a calculator in JavaScript.
This Python3 implementation has been expanded to support multiple ballistic coefficients and custom drag functions, such as those derived from Doppler radar data.
This project exists thanks to all the people who contribute.
Special thanks to:
- David Bookstaber - Ballistics Expert
For help understanding and improving the functionality - Serhiy Yevtushenko - Applied Mathematician
For helping in consultations, testing, and improving edge case compatibility - Nikolay Gekht
For the source code in C# and GO-lang from which this project firstly was forked
This library performs approximate simulations of complex physical processes. Therefore, the calculation results MUST NOT be considered as completely and reliably reflecting actual behavior of projectiles. While these results may be used for educational purpose, they must NOT be considered as reliable for the areas where incorrect calculation may cause making a wrong decision, financial harm, or can put a human life at risk.
THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.