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

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


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-1.1.1.tar.gz (197.0 kB view details)

Uploaded Source

Built Distributions

py_ballisticcalc.exts-1.1.1-py3-none-any.whl (202.3 kB view details)

Uploaded Python 3

py_ballisticcalc.exts-1.1.1-cp312-cp312-win_amd64.whl (312.1 kB view details)

Uploaded CPython 3.12 Windows x86-64

py_ballisticcalc.exts-1.1.1-cp312-cp312-macosx_10_9_universal2.whl (440.3 kB view details)

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

py_ballisticcalc.exts-1.1.1-cp311-cp311-win_amd64.whl (315.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

py_ballisticcalc.exts-1.1.1-cp311-cp311-macosx_10_9_universal2.whl (446.8 kB view details)

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

py_ballisticcalc.exts-1.1.1-cp310-cp310-win_amd64.whl (315.0 kB view details)

Uploaded CPython 3.10 Windows x86-64

py_ballisticcalc.exts-1.1.1-cp310-cp310-macosx_11_0_x86_64.whl (331.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

py_ballisticcalc.exts-1.1.1-cp39-cp39-win_amd64.whl (315.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

py_ballisticcalc.exts-1.1.1-cp39-cp39-macosx_11_0_x86_64.whl (332.7 kB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

File details

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

File metadata

  • Download URL: py_ballisticcalc.exts-1.1.1.tar.gz
  • Upload date:
  • Size: 197.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for py_ballisticcalc.exts-1.1.1.tar.gz
Algorithm Hash digest
SHA256 7e8b1be837d04edc454a08ab440753b3933adb0e299323af320f2b2ac8d9c30c
MD5 289ee8f28354961d1d35ee98ea211041
BLAKE2b-256 b42156bdef17c22f55a974db19ecdcf63d8ba8dc93ef48b43e201aba7042abd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d06821c807f156f4249789df2bf066402198e32727ec59f39657dc408c154b2f
MD5 934b7cc88484ad786479c4a639221740
BLAKE2b-256 0513dbc7b319ef445906daa862293a44e0e1c1d3d1001a3ec249f412f463e189

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 55cae480d376d2442186ad198e4efd42497804b591187113e4534827c2c6a0d2
MD5 531656bc9d948d5fc7a7795bdfb1c079
BLAKE2b-256 650af6f6e64aa53c247ce20b972aa23ae23339dfa378f3f3c07d50f54a4b1668

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.1-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ca75a03eed05b058237574fefb3f28a521dc81e23917cd70b491d8816b0eba22
MD5 c17dd36439c13018e58400c93d01e794
BLAKE2b-256 83b64cd1c1b9b5f6fd41413588f1e92d387d73c735ae2e1cb7275dc26da2d269

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 86a20568b10ffdb6f2dd3ce60b5340fe63173c53ee3c490927ae9429e1654cc1
MD5 17e60783fb8905f6c2fa63c3e7a7f69a
BLAKE2b-256 fe2c3944452f476d70554b2ff23dbe263db26ad2e44240e63d36e4ef4b8c64b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 5d233ce2ad10dd55a1086d17db86a679d30670cc74ac15c8573cb051a98c3565
MD5 9113bd54ce41834d292265bf117d9641
BLAKE2b-256 e264f9dfdf29a076a5bd0650f6dcc6e440db2887e62b8197170528fde700e772

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 88c30ecbb53c11051a97014980ca5d60535b487bd0b21f748e2ebac1b5bf9607
MD5 54a9550970e700f72671616cb21feeca
BLAKE2b-256 d4408302b33376a98d32049320e5e55171eebc7db3c8450161dbe03d77e3c7d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.1-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 e6d253a3d78369e18c9ba59dc0edc8e6e5ffd41b3faaec3e6f00aef5291b10df
MD5 a5d235d291d89b557fbc9feacf2c3307
BLAKE2b-256 ea4f87895b903a1201a5eacac406a3dd575619e2184a9acc8338a7303caceb84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 bac7fce6ab8633c301bb5b8c2c4b47547592c9c087e914287f72dc4c39eb5bf6
MD5 061ef4283fb4fba1fc81919607eda387
BLAKE2b-256 b7586cdd91d37c1bba34e688aee40bf141e3b49bd69eceecf71d8f35773ea3fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.1-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 6a6e8aac04e648cdcbc0e355191790773bc00ad15f8c435cd9ffcc8f499ca6e0
MD5 1203b1de78b5f3c54a46dea853ec663b
BLAKE2b-256 9bca728094df7995d6326f3272cd05ee5533cd7f03295dda62df94b3214c204c

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