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


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

py_ballisticcalc-1.1.0b9.tar.gz (226.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

py_ballisticcalc-1.1.0b9-py3-none-any.whl (224.5 kB view details)

Uploaded Python 3

py_ballisticcalc-1.1.0b9-cp312-cp312-win_amd64.whl (333.1 kB view details)

Uploaded CPython 3.12Windows x86-64

py_ballisticcalc-1.1.0b9-cp312-cp312-macosx_10_9_universal2.whl (460.6 kB view details)

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

py_ballisticcalc-1.1.0b9-cp311-cp311-win_amd64.whl (336.3 kB view details)

Uploaded CPython 3.11Windows x86-64

py_ballisticcalc-1.1.0b9-cp311-cp311-macosx_10_9_universal2.whl (465.5 kB view details)

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

py_ballisticcalc-1.1.0b9-cp310-cp310-win_amd64.whl (335.6 kB view details)

Uploaded CPython 3.10Windows x86-64

py_ballisticcalc-1.1.0b9-cp310-cp310-macosx_11_0_x86_64.whl (352.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

py_ballisticcalc-1.1.0b9-cp39-cp39-win_amd64.whl (336.3 kB view details)

Uploaded CPython 3.9Windows x86-64

py_ballisticcalc-1.1.0b9-cp39-cp39-macosx_11_0_x86_64.whl (353.0 kB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

File details

Details for the file py_ballisticcalc-1.1.0b9.tar.gz.

File metadata

  • Download URL: py_ballisticcalc-1.1.0b9.tar.gz
  • Upload date:
  • Size: 226.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for py_ballisticcalc-1.1.0b9.tar.gz
Algorithm Hash digest
SHA256 9020dc2946e22091a35a88ff5aa8af62e8c1461b5403c7eabc3fffa0008e93b2
MD5 6e7604a3dfd7ed20dab59c0c06131ca4
BLAKE2b-256 ecface15d462df329e0d8ffc8b9e568cc8d0717265fd224d032384767e958b28

See more details on using hashes here.

File details

Details for the file py_ballisticcalc-1.1.0b9-py3-none-any.whl.

File metadata

File hashes

Hashes for py_ballisticcalc-1.1.0b9-py3-none-any.whl
Algorithm Hash digest
SHA256 0dc8d9396e4a241318e95b7c806f3c055612d99969adac447124fe60e026d256
MD5 32e17a970bec950db2ab7a42faba7c2d
BLAKE2b-256 982e4bc5874790bb1df169ab92c2607b8c254e022cf98e9475f0238a57420b1c

See more details on using hashes here.

File details

Details for the file py_ballisticcalc-1.1.0b9-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc-1.1.0b9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a4c0fa329322a7ffe8856ae532e2a25d55ee45ae1bed780143e687a6b362cbc9
MD5 c508ac595d9b61aade7c986be1b05fab
BLAKE2b-256 6e8c99fb9de2000c58d3edbe89fd5690cbe34c66e4eab682b1a86d6ae89e2b5c

See more details on using hashes here.

File details

Details for the file py_ballisticcalc-1.1.0b9-cp312-cp312-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for py_ballisticcalc-1.1.0b9-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d44f66dfc1574e1a841abc0542e662e6a10f41eaea4f664132539528b2aae518
MD5 996d5ec3a5835c3552198b5b87f19442
BLAKE2b-256 1bf96d3babb2b3b7e2724efee46014892f1a9881093c593988a4292c302287c2

See more details on using hashes here.

File details

Details for the file py_ballisticcalc-1.1.0b9-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc-1.1.0b9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 92ee14f7caa86754a56cd77ce13687f60651705c661f1e5950fc902a81b14402
MD5 54db787b96b0cc6798aed8ce83fd54d5
BLAKE2b-256 4d3c286c719fe810bae75d848b9ca992874cb41ecd7b5f340aa405245852bb78

See more details on using hashes here.

File details

Details for the file py_ballisticcalc-1.1.0b9-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for py_ballisticcalc-1.1.0b9-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 780d943ca3d9ba0f45d770531f5157ad49dc0241414d6dac14531fca28528fdd
MD5 0ad4de9291b7a9a5e4f557958f901ea2
BLAKE2b-256 776632cde931ee60605169adc38bd8716d114ba56e8f02df9bfbc9b7bf210457

See more details on using hashes here.

File details

Details for the file py_ballisticcalc-1.1.0b9-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc-1.1.0b9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6771a08162a710b2abced7ebd9db5b4506144692fdfadac47b232786f694c0b4
MD5 e08c44918023be2b1eb1d40e4eafa8ea
BLAKE2b-256 8722ab425ca8249f19aef713d94e28bcad29d7bcfbfb3198fdd4a351e87655d5

See more details on using hashes here.

File details

Details for the file py_ballisticcalc-1.1.0b9-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc-1.1.0b9-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 f989e6d229af0e2562790920b4ef2bcf0f3218068a94974e2caef88c318613ca
MD5 8fa5722a78074a2641bca802d5e73429
BLAKE2b-256 4bd54daa89dcda8b317309ddd7623fe3be2aceb3b46600c00195b7493d17e186

See more details on using hashes here.

File details

Details for the file py_ballisticcalc-1.1.0b9-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc-1.1.0b9-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9ff58962079df2f0f92b82b19f12239cbf44536b8b18c858ed0f15416f23640c
MD5 179e43a2caeab229bb841436fae8d530
BLAKE2b-256 a2f2133d3906550c00d56aed72fcc6f0bc36ede1ee7e7827666d65a0f35a46ae

See more details on using hashes here.

File details

Details for the file py_ballisticcalc-1.1.0b9-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for py_ballisticcalc-1.1.0b9-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 6865c2e6e837e250dcf5bcfc85f06d25f716e090a97c372314e2c1c1b9023104
MD5 2f753e7a85333d433ab0ada60a53c111
BLAKE2b-256 9f7874e358392c8917549dee355c1ed886001c1f7bfe5aff9146edf7d6ccda0c

See more details on using hashes here.

Supported by

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