Skip to main content

ballistics-engine

High-performance ballistics trajectory engine with professional physics modeling.

Features

  • Professional-grade trajectory calculations with multiple drag models (G1, G7, G8)
  • Advanced physics including wind effects and atmospheric modeling
  • Fast Rust implementation with Python bindings via PyO3
  • Imperial units API (grains, fps, yards, inches) with automatic metric conversion

Installation

pip install ballistics-engine

Quick Start

from ballistics_engine import BallisticInputs, TrajectorySolver, WindConditions, AtmosphericConditions, DragModel

# Create ballistic inputs (all imperial units)
inputs = BallisticInputs(
    bc=0.505,                        # G7 BC
    bullet_weight_grains=168,        # grains
    muzzle_velocity_fps=2650,        # feet per second
    bullet_diameter_inches=0.308,    # inches
    bullet_length_inches=1.24,       # inches
    sight_height_inches=1.5,         # inches above bore
    zero_distance_yards=100,         # yards
    twist_rate_inches=11.25,         # inches per turn
)
inputs.drag_model = DragModel.g7()  # Use G7 drag model

# Create wind conditions (optional)
wind = WindConditions(
    speed_mph=10,                    # mph
    direction_degrees=90,            # degrees (0=headwind, 90=from right)
)

# Create atmospheric conditions (optional)
atmosphere = AtmosphericConditions(
    temperature_f=59,                # Fahrenheit
    pressure_inhg=29.92,             # inHg
    humidity_percent=50,             # percent
    altitude_feet=0,                 # feet
)

# Solve trajectory
solver = TrajectorySolver(inputs, wind=wind, atmosphere=atmosphere)
result = solver.solve()

# Print results
print(f"Max range: {result.max_range_yards:.1f} yards")
print(f"Time of flight: {result.time_of_flight:.2f} seconds")
print(f"Impact velocity: {result.impact_velocity_fps:.1f} fps")
print(f"Impact energy: {result.impact_energy_ftlbs:.1f} ft-lbs")

# Iterate through trajectory points
for point in result.points:
    print(f"Time: {point.time:.2f}s, X: {point.x:.1f}yd, Y: {point.y:.3f}yd, V: {point.velocity_fps:.1f}fps")

Units

The Python API uses imperial units for convenience:

  • Mass: grains (gr)
  • Velocity: feet per second (fps)
  • Distance: yards (yd) and inches (in)
  • Pressure: inches of mercury (inHg)
  • Temperature: Fahrenheit (°F)
  • Wind speed: miles per hour (mph)

All conversions to metric (used internally by the Rust engine) are handled automatically.

API Reference

BallisticInputs

Main input parameters for trajectory calculation.

Parameters:

  • bc (float): Ballistic coefficient
  • bullet_weight_grains (float): Bullet mass in grains
  • muzzle_velocity_fps (float): Muzzle velocity in fps
  • bullet_diameter_inches (float): Bullet diameter in inches
  • bullet_length_inches (float): Bullet length in inches
  • sight_height_inches (float): Sight height above bore in inches
  • zero_distance_yards (float): Zero distance in yards
  • shooting_angle_degrees (float): Uphill/downhill angle in degrees
  • twist_rate_inches (float): Barrel twist rate (inches per turn)
  • is_right_twist (bool): True for right-hand twist (default: True)

WindConditions

Wind parameters.

Parameters:

  • speed_mph (float): Wind speed in mph (default: 0)
  • direction_degrees (float): Wind direction in degrees (0=headwind, 90=from right, default: 0)

AtmosphericConditions

Atmospheric parameters.

Parameters:

  • temperature_f (float): Temperature in Fahrenheit (default: 59)
  • pressure_inhg (float): Barometric pressure in inHg (default: 29.92)
  • humidity_percent (float): Relative humidity percentage (default: 50)
  • altitude_feet (float): Altitude in feet (default: 0)

TrajectorySolver

Trajectory calculation engine.

Methods:

  • __init__(inputs, wind=None, atmosphere=None): Create solver with inputs
  • solve(): Calculate trajectory, returns TrajectoryResult

TrajectoryResult

Trajectory calculation results.

Properties:

  • max_range_yards (float): Maximum range in yards
  • max_height_yards (float): Maximum height in yards
  • time_of_flight (float): Total flight time in seconds
  • impact_velocity_fps (float): Impact velocity in fps
  • impact_energy_ftlbs (float): Impact energy in ft-lbs
  • points (list[TrajectoryPoint]): List of trajectory points

TrajectoryPoint

Individual point along trajectory.

Properties:

  • time (float): Time in seconds
  • x (float): Downrange distance in yards
  • y (float): Vertical position in yards (relative to line of sight)
  • z (float): Lateral position in yards
  • velocity_fps (float): Velocity in fps
  • energy_ftlbs (float): Kinetic energy in ft-lbs

DragModel

Drag model selection.

Static methods:

  • DragModel.g1(): G1 drag model (flat base)
  • DragModel.g7(): G7 drag model (boat tail)
  • DragModel.g8(): G8 drag model (boat tail with meplat)

bridge_call(request_json: str) -> str

The engine's versioned JSON command bridge: one request envelope in, one response envelope out, both as strings. It is a transport onto the engine's own service layer, so it reaches corrections.bc5d_table_path and atmosphere.pressure_reference, which the typed classes above cannot carry at all. It is also the safer route to effects.wind_shear_model: the inputs dict has accepted wind_shear_model for some time, but it takes any string and silently resolves an unrecognised one to the power law, where the bridge validates it and names the offending field.

import json
from ballistics_engine import bridge_call

response = json.loads(bridge_call(json.dumps({
    "api_version": 1,
    "command": "solve",
    "request": {
        "schema_version": 1,
        "projectile": {"mass_kg": 0.01134, "diameter_m": 0.00782, "length_m": 0.0338,
                       "drag_model": "G7", "ballistic_coefficient": 0.243},
        "rifle": {"muzzle_velocity_mps": 823.0, "sight_height_m": 0.0381},
        "shot": {"max_range_m": 1000.0, "zero_distance_m": 100.0},
        "atmosphere": {}, "wind": {"speed_mps": 4.47, "direction_from_rad": 1.5708},
        "solver": {}, "effects": {"wind_shear_model": "logarithmic"},
        "sampling": {"interval_m": 100.0},
    },
})))

if response["ok"]:
    print(response["result"]["samples"][-1])
else:
    print(response["error"]["code"], response["error"]["message"])

Unlike the rest of this API, failures come back inside the returned JSON rather than as a Python exception — a bad envelope, an unknown command or an invalid field all return a well-formed {"ok": false, "api_version": 1, "engine_version": "...", "error": {"code": ..., "message": ...}} document. The wrapper returns the string verbatim; parsing and error handling are the caller's.

Unlike the classes above, the bridge speaks SI units throughout (kg, m, m/s, K, Pa, radians), because it is the engine's own wire contract.

Ask meta.capabilities for the command list this wheel can actually run — it is build-dependent, and this wheel links the engine with default features off, so the PDF- and profile-import-gated commands are not compiled in.

License

Dual licensed under MIT or Apache-2.0.

Links

Metadata

Release files for ballistics-engine 0.37.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ballistics-engine 0.37.0
File Size Uploaded
ballistics_engine-0.37.0.tar.gz 61.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for ballistics-engine 0.37.0
File
ballistics_engine-0.37.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
ballistics_engine-0.37.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
ballistics_engine-0.37.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
ballistics_engine-0.37.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
ballistics_engine-0.37.0-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 5.3 MB

Release files / ballistics_engine-0.37.0.tar.gz

Download URL ballistics_engine-0.37.0.tar.gz
Size 61.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5cb5167ceefc7b8c8067f318470c7d2f06cc56c3dbda6435977e38860241acc5
BLAKE2b-256 checksum
How to use checksums
4586c7d3232a8856300a3e35ab2c6dc2da1c6437c3de475d194db8fa53fa9fce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / ballistics_engine-0.37.0-cp38-abi3-win_amd64.whl

Download URL ballistics_engine-0.37.0-cp38-abi3-win_amd64.whl
Size 1.0 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fa6b6e244d209f154258fe8f227b2be749f9d288a51c4e9915b00df7c268a848
BLAKE2b-256 checksum
How to use checksums
b1c3a8e63f137180b5150eb913479910d68d9c36d67f2b8af338af2b32094785
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / ballistics_engine-0.37.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL ballistics_engine-0.37.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
04f26628f14dd37e63b8a8efbe7c739410bf84cdf63da5b87e4181c06173035d
BLAKE2b-256 checksum
How to use checksums
84300157f55caf25c3e904914b5754752c199895f9e0c1bdccc6cb20460ae64a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / ballistics_engine-0.37.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL ballistics_engine-0.37.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.0 MB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a21242414aa1a4b2ac2dbca0addaee45218f35b6b1efe57c5a6e5ccf993297b0
BLAKE2b-256 checksum
How to use checksums
de2a7cf24b1cc2315fa1b947c4386473006d54698ae426e5c0268af0bdb7cbcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / ballistics_engine-0.37.0-cp38-abi3-macosx_11_0_arm64.whl

Download URL ballistics_engine-0.37.0-cp38-abi3-macosx_11_0_arm64.whl
Size 998.6 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
48c9de6e35f9346ec39d22619270722d98e64bf9a250b550a67910f0a660e1bf
BLAKE2b-256 checksum
How to use checksums
0d90971a0f82941c4ca1dbe511ab91b2a70d44498ca89d17b9138bca4fdc05cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / ballistics_engine-0.37.0-cp38-abi3-macosx_10_12_x86_64.whl

Download URL ballistics_engine-0.37.0-cp38-abi3-macosx_10_12_x86_64.whl
Size 1.1 MB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
21f57c9133d82b5dbf9b566eec9e264549787a1f561158e345e28a1e3f0cce02
BLAKE2b-256 checksum
How to use checksums
3d68c20339de269eb945392a567dcef6e9553ea5418e8c3ef7f5bf2e0b584e9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

0.47.0

6 release files

0.46.0

6 release files

0.44.0

6 release files

0.43.0

6 release files

0.42.0

6 release files

0.41.0

6 release files

0.40.0

6 release files

0.39.0

6 release files

0.38.0

6 release files

This release

0.37.0 This release

6 release files

0.36.1

6 release files

0.36.0

6 release files

0.35.0

6 release files

0.34.0

6 release files

0.33.4

6 release files

0.33.3

6 release files

0.33.1

6 release files

0.31.0

6 release files

0.30.1

6 release files

0.30.0

6 release files

0.29.0

6 release files

0.28.1

6 release files

0.28.0

6 release files

0.27.1

6 release files

0.27.0

6 release files

0.26.0

6 release files

0.25.2

6 release files

0.25.0

6 release files

0.24.2

6 release files

0.24.1

6 release files

0.24.0

6 release files

0.23.0

6 release files

0.21.5

6 release files

0.21.4

6 release files

0.21.3

6 release files

0.21.2

5 release files

0.21.1

5 release files

0.21.0

5 release files

0.18.3

6 release files

0.18.2

6 release files

0.18.1

6 release files

0.17.0

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page