LGPL library for small arms ballistic calculations (Python 3)
Project description
BallisticCalculator
LGPL library for small arms ballistic calculations (Python 3.9+)
Table of contents
Installation
Latest stable release from pypi**
pip install py-ballisticcalc
Installing from sources
MSVC or GCC required
- Download and install MSVC or GCC depending on target platform
- Use one of the references you need:
# no binary from PyPi
pip install py-ballisticcalc==<version> --no-binary py-ballisticcalc
# master brunch
pip install git+https://github.com/o-murphy/py_ballisticcalc
# specific branch
pip install git+https://github.com/o-murphy/py_ballisticcalc.git@<target_branch_name>
Clone and build
MSVC or GCC required
git clone https://github.com/o-murphy/py_ballisticcalc
cd py_ballisticcalc
python -m venv venv
. venv/bin/activate
pip install cython
python setup.py build_ext --inplace
Usage
The library supports all the popular units of measurement, and adds different built-in methods to define and manipulate it
Unit manipulation syntax:
from py_ballisticcalc.unit import *
# ways to define value in units
# 1. old syntax
unit_in_meter = Distance(100, Distance.Meter)
# 2. short syntax by Unit type class
unit_in_meter = Distance.Meter(100)
# 3. by Unit enum class
unit_in_meter = Unit.METER(100)
# >>> <Distance>: 100.0 m (3937.0078740157483)
# convert unit
# 1. by method
unit_in_yard = unit_in_meter.convert(Distance.Yard)
# 2. using shift syntax
unit_in_yards = unit_in_meter << Distance.Yard # '<<=' operator also supports
# >>> <Distance>: 109.36132983377078 yd (3937.0078740157483)
# get value in specified units
# 1. by method
value_in_km = unit_in_yards.get_in(Distance.Kilometer)
# 2. by shift syntax
value_in_km = unit_in_yards >> Distance.Kilometer # '>>=' operator also supports
# >>> 0.1
# getting unit raw value:
rvalue = Distance.Meter(10).raw_value
rvalue = float(Distance.Meter(10))
# units comparison:
# supports operators like < > <= >= == !=
Distance.Meter(100) == Distance.Centimeter(100) # >>> False, compare two units by raw value
Distance.Meter(100) > 10 # >>> True, compare unit with float by raw value
An example of calculations
from py_ballisticcalc import Velocity, Temperature, Distance
from py_ballisticcalc import DragModel, TableG7
from py_ballisticcalc import Ammo, Atmo, Wind
from py_ballisticcalc import Weapon, Shot, Calculator
from py_ballisticcalc import Settings as Set
# set global library settings
Set.Units.velocity = Velocity.FPS
Set.Units.temperature = Temperature.Celsius
# Set.Units.distance = Distance.Meter
Set.Units.sight_height = Distance.Centimeter
Set.set_max_calc_step_size(Distance.Foot(1))
Set.USE_POWDER_SENSITIVITY = True # enable muzzle velocity correction my powder temperature
# define params with default units
weight, diameter = 168, 0.308
# or define with specified units
length = Distance.Inch(1.282) # length = Distance(1.282, Distance.Inch)
weapon = Weapon(9, 100, 2)
dm = DragModel(0.223, TableG7, weight, diameter)
ammo = Ammo(dm, length, 2750, 15)
ammo.calc_powder_sens(2723, 0)
zero_atmo = Atmo.icao(100)
# defining calculator instance
calc = Calculator(weapon, ammo, zero_atmo)
current_atmo = Atmo(110, 1000, 15, 72)
current_winds = [Wind(2, 90)]
shot = Shot(1500, atmo=current_atmo, winds=current_winds)
shot_result = calc.fire(shot, trajectory_step=Distance.Yard(100))
for p in shot_result:
print(p.formatted())
Example of the formatted output:
python -m py_ballisticcalc.example
['0.00 s', '0.000 m', '2750.0 ft/s', '2.46 mach', '-9.000 cm', '0.00 mil', '0.000 cm', '0.00 mil', '3825 J']
['0.12 s', '100.000 m', '2528.6 ft/s', '2.26 mach', '0.005 cm', '0.00 mil', '-3.556 cm', '-0.36 mil', '3233 J']
['0.26 s', '200.050 m', '2317.2 ft/s', '2.08 mach', '-7.558 cm', '-0.38 mil', '-13.602 cm', '-0.69 mil', '2715 J']
['0.41 s', '300.050 m', '2116.6 ft/s', '1.90 mach', '-34.843 cm', '-1.18 mil', '-30.956 cm', '-1.05 mil', '2266 J']
['0.57 s', '400.000 m', '1926.5 ft/s', '1.73 mach', '-85.739 cm', '-2.18 mil', '-57.098 cm', '-1.45 mil', '1877 J']
['0.75 s', '500.000 m', '1745.0 ft/s', '1.56 mach', '-165.209 cm', '-3.37 mil', '-94.112 cm', '-1.92 mil', '1540 J']
['0.95 s', '600.000 m', '1571.4 ft/s', '1.41 mach', '-279.503 cm', '-4.74 mil', '-144.759 cm', '-2.46 mil', '1249 J']
Contributors
This project exists thanks to all the people who contribute.
Special thanks to:
- David Bookstaber - Ballistics Expert, Financial Engineer
For the help in understanding and improvement of some calculation methods - Nikolay Gekht
For the sources code on C# and GO-lang from which this project firstly was forked from
About project
The library provides trajectory calculation for projectiles including for various applications, including air rifles, bows, firearms, artillery and so on.
3DF model that is used in this calculator is rooted in old C sources of version 2 of the public version of JBM calculator, ported to C#, optimized, fixed and extended with elements described in Litz's "Applied Ballistics" book and from the friendly project of Alexandre Trofimov and then ported to Go.
Now it's also ported to python3 and expanded to support calculation trajectory by multiple ballistics coefficients and using custom drag data (such as Doppler radar data ©Lapua, etc.)
The online version of Go documentation is located here: https://godoc.org/github.com/gehtsoft-usa/go_ballisticcalc
C# version of the package is located here: https://github.com/gehtsoft-usa/BallisticCalculator1
The online version of C# API documentation is located here: https://gehtsoft-usa.github.io/BallisticCalculator/web-content.html
Go documentation can be obtained using godoc tool.
The current status of the project is ALPHA version.
RISK NOTICE
The library performs very limited simulation of a complex physical process and so it performs a lot of approximations. Therefore, the calculation results MUST NOT be considered as completely and reliably reflecting actual behavior or characteristics 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file py_ballisticcalc.exts-1.1.2.tar.gz
.
File metadata
- Download URL: py_ballisticcalc.exts-1.1.2.tar.gz
- Upload date:
- Size: 197.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fe39038a539b3ccf00a13e057c4d9f21bfeb741dd34abca2181bd0af9600f67 |
|
MD5 | 65604f85d5b0955c1ea483d2dbb3069d |
|
BLAKE2b-256 | 5facaa1cb8fa0bb681b8af57c8d6628af38de1732ab7cb7664b412142a56b405 |
File details
Details for the file py_ballisticcalc.exts-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: py_ballisticcalc.exts-1.1.2-py3-none-any.whl
- Upload date:
- Size: 202.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3801e3e608e6836b7963bdda345fecc3bf3ee7a1d79041f444986f83bdcedb8d |
|
MD5 | 3d218387bdff2b2a4016c6315111dc71 |
|
BLAKE2b-256 | 8e6a29b718b6372b8e38a02d5092532fa6e4f2807cfbc688afc43f15924b2341 |
File details
Details for the file py_ballisticcalc.exts-1.1.2-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: py_ballisticcalc.exts-1.1.2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 311.5 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dd4a51f13ae8b1c6999b20ee9d3a97720398b2ce44ff89bd7616be88c518922 |
|
MD5 | 3e9eca3e3ffc6d7ba3c1d72974c8bf74 |
|
BLAKE2b-256 | 733292db77ceeed228a1b1ed953758aaa96a2613b45dce67559b28db1e39e456 |
File details
Details for the file py_ballisticcalc.exts-1.1.2-cp312-cp312-macosx_10_9_universal2.whl
.
File metadata
- Download URL: py_ballisticcalc.exts-1.1.2-cp312-cp312-macosx_10_9_universal2.whl
- Upload date:
- Size: 440.2 kB
- Tags: CPython 3.12, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1c164d9aaf6276f04d535d6a6ec1e3b73a9b568fe8d0ab4bfc9d930bc8a13fb |
|
MD5 | 871efbc220e057ca6d181b8454e72f0a |
|
BLAKE2b-256 | d6f0f627a2b43bc63409e3b904e1544a1676b991508b1e94bcfd0b5da36c2aa5 |
File details
Details for the file py_ballisticcalc.exts-1.1.2-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: py_ballisticcalc.exts-1.1.2-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 315.4 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab27faaf27292ae72df4d5fd4a67448ccf62aca6af93295c080b644cd4b90c18 |
|
MD5 | a67da03c766b60c06d4ad8788a06ea33 |
|
BLAKE2b-256 | 4ca9bbd0a763ab0d4ef3fa5f9638b52dacaaefd4dc810785f16df590f505dbc7 |
File details
Details for the file py_ballisticcalc.exts-1.1.2-cp311-cp311-macosx_10_9_universal2.whl
.
File metadata
- Download URL: py_ballisticcalc.exts-1.1.2-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 446.5 kB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23d891d4d3c301c8f410971235b49e9c698f6e71fa9ffc27e256925b8ad96864 |
|
MD5 | 7f1bbc6e9eef71cab57c106e452fa785 |
|
BLAKE2b-256 | f59790157de3c127f63d822dbbb75fdfc15e46781381bb6616ea8d19642b12a8 |
File details
Details for the file py_ballisticcalc.exts-1.1.2-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: py_ballisticcalc.exts-1.1.2-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 314.7 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 021e2e1bba3a34bd133894f691d11ed706c61d7668da9355193e0b2ac3e16253 |
|
MD5 | bcdb7eaea10e4ad330d9f4c0231ef45d |
|
BLAKE2b-256 | 71e3c78b95bb31b200e97dfe7b92425bde30f15cc7b4e01f87e9bd8a5052df89 |
File details
Details for the file py_ballisticcalc.exts-1.1.2-cp310-cp310-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: py_ballisticcalc.exts-1.1.2-cp310-cp310-macosx_11_0_x86_64.whl
- Upload date:
- Size: 331.6 kB
- Tags: CPython 3.10, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf9cbe6eb829703e5d00a16bffee5228e303557e09ad86383173b148a1688080 |
|
MD5 | 527197c1592cf07e42f1be3672d8fefc |
|
BLAKE2b-256 | 0d3e1e4bfdaaf87f5a784a7cf341d8bbeaddd04d3f1f79faaabed20e176921b2 |
File details
Details for the file py_ballisticcalc.exts-1.1.2-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: py_ballisticcalc.exts-1.1.2-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 315.4 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1de24505d6b24e0c762904d9b264394ca32a9b111f069f209ced8a6e6862ff8b |
|
MD5 | 721c05b6cfc517fef814ff25e4f0dd4a |
|
BLAKE2b-256 | 90c433304f7dfbff905b0d23a1d1f51a002f5bee1b28a650ff705f3da83c90ae |
File details
Details for the file py_ballisticcalc.exts-1.1.2-cp39-cp39-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: py_ballisticcalc.exts-1.1.2-cp39-cp39-macosx_11_0_x86_64.whl
- Upload date:
- Size: 332.6 kB
- Tags: CPython 3.9, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc7622e272197c9a8212a666578ae8729f8c92f446266db129e36a03b795eeb1 |
|
MD5 | 82e2f31006a5df13e6ac6f5ed0dbb97c |
|
BLAKE2b-256 | 33de72ba9460e8a1db3f7a4708fa20b17e5d860e888faf6770130d6652b20532 |