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

Uploaded Source

Built Distributions

py_ballisticcalc.exts-1.1.3-py3-none-any.whl (202.8 kB view details)

Uploaded Python 3

py_ballisticcalc.exts-1.1.3-cp312-cp312-win_amd64.whl (311.5 kB view details)

Uploaded CPython 3.12 Windows x86-64

py_ballisticcalc.exts-1.1.3-cp312-cp312-macosx_10_9_universal2.whl (440.2 kB view details)

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

py_ballisticcalc.exts-1.1.3-cp311-cp311-win_amd64.whl (315.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

py_ballisticcalc.exts-1.1.3-cp311-cp311-macosx_10_9_universal2.whl (446.5 kB view details)

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

py_ballisticcalc.exts-1.1.3-cp310-cp310-win_amd64.whl (314.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

py_ballisticcalc.exts-1.1.3-cp310-cp310-macosx_11_0_x86_64.whl (331.6 kB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

py_ballisticcalc.exts-1.1.3-cp39-cp39-win_amd64.whl (315.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

py_ballisticcalc.exts-1.1.3-cp39-cp39-macosx_11_0_x86_64.whl (332.6 kB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

File details

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

File metadata

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

File hashes

Hashes for py_ballisticcalc.exts-1.1.3.tar.gz
Algorithm Hash digest
SHA256 a7cceaaa5400097b25be58af5b359b8423739434a5e308fb06d1bb34e3d63db8
MD5 59b1e5a2fcf46839ca9abda5a2eb1e8d
BLAKE2b-256 df5f51a9d10685e3cf01734f2e1eea523140a70d68f0582c289bbc9bcfaa9cb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 79cd41836d4fc6ea28b7329057040f5b28674e4c86f9f3a27457d99f6480348b
MD5 3028bdf74133ecaadc19cec7eeb02522
BLAKE2b-256 5ac9b7843c31bebd4d14da002728272105c77521bbaf676ef8249da4a8b89d95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4831089a59154cf06888980edac164eef3e24d63b2bc24b0820fc038d09dc97d
MD5 9c4561ce218eabbd777a7252a6074ee8
BLAKE2b-256 62a622983de3ef12d8c5ef8768304d4f1d80667b94356c884ca6f086181e586b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.3-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e772a2f926463bb8837cf4f55755f5e2253668095ce396f56980994bff899496
MD5 52d9f122b60b1b7864b02f5736ec0201
BLAKE2b-256 db8190abfdaa1e157270e9203092dd1a781d66461b10694511bd7460c5de2b98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b13fb03c7e4ed53d69d3f69557c3be9ff829ab630759ba3f23ed10ad2a369099
MD5 8d3983ae61125c37fd6fa96eb0588d5b
BLAKE2b-256 b7e627f01bc7be95526c0b52e6022f73653af8abf919ad5a8136a7df9e0f0d52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.3-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d5928135c1ae6f240252394d0665fbc4cd5101b043dbce82d5b271f978af7be9
MD5 4da841fef5bca14a8c0a36280f492a71
BLAKE2b-256 9ef59c3efc59c39e9bcce12bdc92bac6dfa842fe71b2bc1c71461aeb7deed2d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 57578adb1b0b7fe795a05df758b21422c3451084bd1e224a9b6bdcb5bff37e8b
MD5 171a45ae408e3f3c1c261a5c2ab1eba5
BLAKE2b-256 5017f0031b89455564b9f482d7ed3cac138a5768391bf77c8d55aeb504e36210

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.3-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 6aefb1fcc17c2ec90ec419235ebbff79dd730bcf77a0e7e4c21bde4cfc48107e
MD5 5e115e997665515a99465662dd3e125e
BLAKE2b-256 c84d3e30312d004435a8664f1eb9067fda77062ed69e95287a12f5260d8ee395

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f8c313376c7c455e45d1fa219923f9f1371e9acf2f912ac19117f9bef03c13eb
MD5 dd7ad2aa6001b16b4971bf2a5e103077
BLAKE2b-256 b4ef449c70963c0ee1c5c1e5aabf4ee02e1e19ba57baecdda103e223c6662e27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_ballisticcalc.exts-1.1.3-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 318aa9adb642600ee29417d476ff02b71d56020f31c06cd1f13f1600c61863e8
MD5 4a5ad7ef7e513ca87b5f519f23c49f18
BLAKE2b-256 24efb44fcaf9a615c783ecdde7a8b03e21b4fb3ec685cd50996a316433b83813

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