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 prefer_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 prefer_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))

# prefer_units comparison:
# supports operators like < > <= >= == !=
Distance.Meter(100) == Distance.Centimeter(100)  # >>> False, compare two prefer_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, PreferredUnits

# Modify default prefer_units
PreferredUnits.velocity = Velocity.FPS
PreferredUnits.temperature = Temperature.Celsius
PreferredUnits.distance = Distance.Meter
PreferredUnits.sight_height = Distance.Centimeter

Settings.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 prefer_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.0.tar.gz (111.5 kB view details)

Uploaded Source

Built Distributions

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

Uploaded Python 3

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

Uploaded CPython 3.12 Windows x86-64

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

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

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

Uploaded CPython 3.11 Windows x86-64

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

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

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 macOS 11.0+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 macOS 11.0+ x86-64

File details

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

File metadata

  • Download URL: py_ballisticcalc.exts-2.0.0.tar.gz
  • Upload date:
  • Size: 111.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for py_ballisticcalc.exts-2.0.0.tar.gz
Algorithm Hash digest
SHA256 da0343fa50f1f8fbe0568dc1411a8fd5071588b29451174fdf49861ffa05375f
MD5 376b422d8d89e9f60401dfa771ee0b71
BLAKE2b-256 62c52c7d7fe3331cfb16f79e496fde39fd16b5e87b61f69c70b4faaab382873c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8c9a94e7bafb3cb778d0cff78ef1a65fa72da81a8fa8f7993c6d3feb793474c
MD5 0a0a59fcaaad48ffa29001225de6fc7c
BLAKE2b-256 1df56685e15dc62a5951bea6ad2bb24ab4f6301df02f71e8a9d641f0c9d57ada

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f3e52238c3691594ad059e900e691edf6a90731c61ca2b686bc07e1e0a5e69bc
MD5 d56265e3a84aec360a74402fbce8926d
BLAKE2b-256 03c160dad99be115f1dd5657cbcec9839994aaab33a931f5c3907d9057670b27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1da16d4adbae82ecd48d9159c2e24318f1612439de38d6173fc015b75b8b36aa
MD5 be43e8d5e01e6e118624288807e10ee6
BLAKE2b-256 587358df075ef65e6362c6ddca17875d9e46d527bf9276be7c8a24b7facb6c7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e3803f4b390bd9ac1eca351970c19da9e6ca1d7b108c725b676f7a0e973c9ccf
MD5 242978693e10b1f1f7894724239a817d
BLAKE2b-256 e22ea79595a3bc9fe7c76c41fd14b5e08a7d4ddd964f41024967b75933306b21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ee956d59babd748ae23104a96d2da8d011a67b97e0f44d9700dbd428741620a8
MD5 e6c8d6978fd80277ae64009c694ba5bf
BLAKE2b-256 0bceda9dc6ace294ff43f8d30f0478003b00c96a99af44bd39019fde4e3d8335

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fe2a2f70aa4fe5926b0699896c4e522169cc5b703b2085ec0027fcb8b762fa43
MD5 a093cc0f7084bd69ef2361db57328d75
BLAKE2b-256 bc950bad8f80829781f834b439fe5f86115267cc27adc2f47f02e4c61e61627d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 7e9c529e0fc180bcbd00d8b7908321d622abba0dd9240f507efd7d2c92d6eb01
MD5 f4c988985553e5e3dee5ae57b864677b
BLAKE2b-256 253aa9919cbc43ac48f8b875aff55063baf38076e85c2fa5e66e97c8e8d7cc81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c36cb986b59d218c557804a99caf94218e8e93716b927a1d0971eea1bb3e4d2e
MD5 0ed21a3f465478ff6311e10299b47e8d
BLAKE2b-256 2f962f7e7f7463567359824c338447034dacd91b33650f42c68f0ed18d0d7f04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-2.0.0-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 0c8f7793577b01d01d980898f4f1bcd9f9708172bdeb5bbbfb14e72722d59931
MD5 67012c458f4130f506e5437b037d9dc5
BLAKE2b-256 92688d7a0f7c8092fea39429658cf2fa4c6969a40bad1182dbed67044dadf7ce

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