Skip to main content

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

# Using precompiled backend (improves performance)
pip install py-ballisticcalc[exts]

# Using matplotlib and pandas uses additional dependencies
pip install py-ballisticcalc[charts]

Using matplotlib and pandas uses additional dependencies

pip install py-ballisticcalc[charts]

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>

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 *
from py_ballisticcalc import Settings as Set

# Modify default units
Set.Units.velocity = Velocity.FPS
Set.Units.temperature = Temperature.Celsius
Set.Units.distance = Distance.Meter
Set.Units.sight_height = Distance.Centimeter

Set.USE_POWDER_SENSITIVITY = True  # Correct muzzle velocity for powder temperature

# Define ammunition parameters
weight, diameter = 168, 0.308  # Numbers will be assumed to use default Settings.Units
length = Distance.Inch(1.282)  # Or declare units explicitly
dm = DragModel(0.223, TableG7, weight, diameter, length)
ammo = Ammo(dm, 2750, 15)
ammo.calc_powder_sens(2723, 0)
gun = Weapon(sight_height=9, twist=12)
current_atmo = Atmo(110, 29.8, 15, 72)
current_winds = [Wind(2, 90)]
shot = Shot(weapon=gun, ammo=ammo, atmo=current_atmo, winds=current_winds)
calc = Calculator()
calc.set_weapon_zero(shot, Distance.Meter(100))

shot_result = calc.fire(shot, trajectory_range=1000, trajectory_step=100)

for p in shot_result:
    print(p.formatted())

Example of the formatted output:

python -m py_ballisticcalc.example
('0.000 s', '0.0 m', '2750.0 ft/s', '2.46 mach', '-3.5 inch', '-3.5 inch', '0.00 mil', '0.0 inch', '0.00 mil', '0.0 m', '0.0939 °', '-4.062e-03', '0.000', '2821 ft·lb', '880 lb', 8)
('0.125 s', '100.1 m', '2526.5 ft/s', '2.26 mach', '0.0 inch', '0.0 inch', '0.00 mil', '0.2 inch', '0.05 mil', '100.1 m', '0.0068 °', '-4.062e-03', '0.665', '2381 ft·lb', '683 lb', 9)
('0.260 s', '200.0 m', '2313.5 ft/s', '2.07 mach', '-3.0 inch', '-3.0 inch', '-0.39 mil', '0.8 inch', '0.10 mil', '200.0 m', '-0.0967 °', '-4.062e-03', '0.633', '1996 ft·lb', '524 lb', 8)
('0.409 s', '300.1 m', '2111.2 ft/s', '1.89 mach', '-13.8 inch', '-13.8 inch', '-1.19 mil', '1.9 inch', '0.16 mil', '300.1 m', '-0.2207 °', '-4.062e-03', '0.599', '1663 ft·lb', '398 lb', 8)
('0.572 s', '400.1 m', '1919.6 ft/s', '1.72 mach', '-33.9 inch', '-33.9 inch', '-2.19 mil', '3.5 inch', '0.22 mil', '400.1 m', '-0.3701 °', '-4.062e-03', '0.570', '1374 ft·lb', '299 lb', 8)
('0.751 s', '500.0 m', '1736.8 ft/s', '1.56 mach', '-65.4 inch', '-65.4 inch', '-3.38 mil', '5.7 inch', '0.30 mil', '500.0 m', '-0.5516 °', '-4.062e-03', '0.545', '1125 ft·lb', '222 lb', 8)
('0.951 s', '600.1 m', '1561.9 ft/s', '1.40 mach', '-110.7 inch', '-110.7 inch', '-4.77 mil', '8.7 inch', '0.37 mil', '600.1 m', '-0.7748 °', '-4.062e-03', '0.521', '910 ft·lb', '161 lb', 8)
('1.173 s', '700.0 m', '1395.2 ft/s', '1.25 mach', '-173.1 inch', '-173.1 inch', '-6.40 mil', '12.6 inch', '0.47 mil', '700.0 m', '-1.0525 °', '-4.062e-03', '0.495', '726 ft·lb', '115 lb', 8)
('1.423 s', '800.0 m', '1238.1 ft/s', '1.11 mach', '-257.0 inch', '-257.0 inch', '-8.31 mil', '17.6 inch', '0.57 mil', '800.0 m', '-1.4030 °', '-4.062e-03', '0.462', '572 ft·lb', '80 lb', 8)
('1.705 s', '900.1 m', '1097.8 ft/s', '0.98 mach', '-368.2 inch', '-368.2 inch', '-10.58 mil', '24.1 inch', '0.69 mil', '900.1 m', '-1.8503 °', '-9.633e-03', '0.333', '450 ft·lb', '56 lb', 8)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_ballisticcalc.exts-2.0.0b1.tar.gz (201.8 kB view details)

Uploaded Source

Built Distributions

py_ballisticcalc.exts-2.0.0b1-py3-none-any.whl (207.2 kB view details)

Uploaded Python 3

py_ballisticcalc.exts-2.0.0b1-cp312-cp312-win_amd64.whl (319.4 kB view details)

Uploaded CPython 3.12 Windows x86-64

py_ballisticcalc.exts-2.0.0b1-cp312-cp312-macosx_10_9_universal2.whl (450.5 kB view details)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

py_ballisticcalc.exts-2.0.0b1-cp311-cp311-win_amd64.whl (322.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

py_ballisticcalc.exts-2.0.0b1-cp311-cp311-macosx_10_9_universal2.whl (455.4 kB view details)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

py_ballisticcalc.exts-2.0.0b1-cp310-cp310-win_amd64.whl (322.0 kB view details)

Uploaded CPython 3.10 Windows x86-64

py_ballisticcalc.exts-2.0.0b1-cp310-cp310-macosx_11_0_x86_64.whl (338.4 kB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

py_ballisticcalc.exts-2.0.0b1-cp39-cp39-win_amd64.whl (322.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

py_ballisticcalc.exts-2.0.0b1-cp39-cp39-macosx_11_0_x86_64.whl (339.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

File details

Details for the file py_ballisticcalc.exts-2.0.0b1.tar.gz.

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0b1.tar.gz
Algorithm Hash digest
SHA256 2cb83c6843b77f06bf18ad5ada6c72c23a481f8ff8f92659f6ff6bc707011c6e
MD5 5b5f8d962d1ff05bc1dc3db712108ed0
BLAKE2b-256 f4bd420d0379a1e7d10f22d89bb7cebb240944231f62b6c2ebc1700e757e7872

See more details on using hashes here.

File details

Details for the file py_ballisticcalc.exts-2.0.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c9dc6cb5d1755929e672fd279927df5ecddf6bf93598000f339f49d6e6464bd
MD5 121179f84d00b9c17ed920dcabbead7b
BLAKE2b-256 7e474907cbe3d9e45ad0b998be594e66904e5b1c5b4676580df07ceddf936c42

See more details on using hashes here.

File details

Details for the file py_ballisticcalc.exts-2.0.0b1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0b1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8d5971ab7b06071ce270024b402824a16ca1dc8f1053a1656b38eadf9dd9f654
MD5 83f995a79613b8fb4ccfacaf5b4cf02a
BLAKE2b-256 a50ae3c8fcc2d17dc8a2c68681f2fe1bdf7aeea9085dbd00b18985e77bc7f0d4

See more details on using hashes here.

File details

Details for the file py_ballisticcalc.exts-2.0.0b1-cp312-cp312-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0b1-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 109cdf5fde8e9688f1cde1dbef3023648f4ecebaf99d4dafe973f38f26431cbd
MD5 12dd72bdb4dd294581e20c7a9c28c2c0
BLAKE2b-256 9b91138de4b641dfda18b7fa14734a93bf6766f20ebfb9b0ce10373318791848

See more details on using hashes here.

File details

Details for the file py_ballisticcalc.exts-2.0.0b1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0b1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5e848a9178b5bac8cae5828ecc62d884045564d60a4e095106aed768d2849379
MD5 3709592cf75df32ebf0cee6137515cc3
BLAKE2b-256 8bada97c7eb26c5c9d72676f54b90a285f116b426cde39caff03e408396f4d36

See more details on using hashes here.

File details

Details for the file py_ballisticcalc.exts-2.0.0b1-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0b1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d7e8332aa3e0f3075856450e825745a623fdada1fa802a39003c42be8c680c58
MD5 8651067b48845db8e0d06f11a048b46b
BLAKE2b-256 faf8afbf96436a2760e9ea27f2f121cf50588c69abf43162b08f654e91f675d7

See more details on using hashes here.

File details

Details for the file py_ballisticcalc.exts-2.0.0b1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0b1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b55f79e46d444c2f619a86d58735558d6904267111776a63628296c324025df6
MD5 6c78a41d0634c875313df1af4b426224
BLAKE2b-256 61f39e0aa03f5338da3c9acc38f1c61d249046cca4aee110c7c8f00379e7942a

See more details on using hashes here.

File details

Details for the file py_ballisticcalc.exts-2.0.0b1-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0b1-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 b3ef21733b9abe52925e3394f32aa2970af020b19deea3392331277455719541
MD5 8e19f41abb49d40fc3a35f88be3e1b27
BLAKE2b-256 22d65a77df822926a90264a4214c9df1b343c35282e805591b08893ffa3725a1

See more details on using hashes here.

File details

Details for the file py_ballisticcalc.exts-2.0.0b1-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0b1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9db656800b0fcdf659acc8f21ebc7420129ffd17f6573f678933e4b32f76bc46
MD5 f8f6d1f87a0d62acd02b7865eaf6f033
BLAKE2b-256 81c3663629eeb8cf54d8df9b3f8280b16127f53603d0298b38b9540fa7b699d3

See more details on using hashes here.

File details

Details for the file py_ballisticcalc.exts-2.0.0b1-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0b1-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 5807ee93eb5d7afd6ed08d81b6b269c96b46cccc187ca9df80242324f01f8100
MD5 2b0922ac8387c2e41bbbb5f5e66fea26
BLAKE2b-256 97eabe9af71048be47fbb634f6ab672816cc1117e1ebc68014e01c9a2b568bb9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page