Skip to main content

No project description provided

Project description

banner

ballistic-solver is a native C/C++ numerical solver that computes launch angles to intercept moving targets under gravity and quadratic air drag. Unlike vacuum / closed-form approaches, this solver simulates the projectile and solves the intercept numerically, targeting robustness for real-time simulations even when trajectories are strongly curved.


Quick start

Python (wheel)

pip install ballistic-solver

Requires Python >= 3.10.

import ballistic_solver as bs

result = bs.solve(
    relPos0=(120, 30, 5),
    relVel=(2, -1, 0),
    v0=90,
    kDrag=0.002,
)

print(result["theta"], result["phi"], result["miss"])
print(result["success"], result["status"], result["message"])

Signature (actual binding)

solve(relPos0, relVel, v0, kDrag, arcMode=0, params=None) -> dict
  • arcMode accepts 0/1 or "low"/"high" (case-insensitive).
  • Important: the arcMode argument overrides params.arcMode even if params is provided.

Returned dict keys include:

  • success, theta, phi, miss, tStar, relMissAtStar
  • status, message
  • iterations, acceptedSteps, lastLambda, lastAlpha

C ABI (stable interface)

void ballistic_inputs_init(BallisticInputs* in);
int32_t ballistic_solve(const BallisticInputs* in, BallisticOutputs* out);

See ballistic_solver_c_api.h for BallisticInputs/Outputs definitions and defaults.


Demo (Unity)

Highly curved trajectories under strong air drag, still converging to a hit against moving targets.

https://github.com/user-attachments/assets/dcaf7479-cb94-477a-b71e-470a5b4c6004


Key properties

  • Moving targets supported
  • Strong air resistance (quadratic drag) supported
  • Robust in strongly nonlinear regimes (no analytic assumptions)
  • Best-effort result returned even without perfect convergence
  • Explicit success / failure reporting (+ diagnostic message)
  • Stable C ABI for multi-language use
  • Header-only C++ core
  • Low / High arc selection (since v0.2.0)

Arc mode (since v0.2.0)

C ABI convention:

  • arcMode = 0 → Low
  • arcMode = 1 → High

High arc example:

https://github.com/user-attachments/assets/4334ed87-597e-4ad4-b21e-c1a1a17e8cd8


How it works (high level)

  1. Simulate projectile motion using RK4 integration with drag (+ wind in core/C ABI)
  2. Track the closest approach between projectile and target
  3. Express the miss at closest approach as an angular residual
  4. Solve the nonlinear system using damped least squares (Levenberg–Marquardt)
  5. Accelerate Jacobian updates with Broyden-style refinement
  6. Return the best solution found

Failure cases are explicitly detected and reported.


Advanced parameters (C ABI)

BallisticInputs exposes additional controls (all have defaults via ballistic_inputs_init):

  • g (gravity)
  • wind[3] (wind vector)
  • dt (RK4 step)
  • tMax (max sim time)
  • tolMiss (hit tolerance)
  • maxIter (LM iterations)

Note: The current Python binding exposes many tuning parameters via BallisticParams, but does not expose wind as a Python field.


Status codes (SolveStatus)

BallisticOutputs.status / Python result["status"] corresponds to the core enum:

  • 0 = Ok
  • 1 = InvalidInput
  • 2 = InitialResidualFailed
  • 3 = JacobianFailed
  • 4 = LMStepSingular
  • 5 = ResidualFailedDuringSearch
  • 6 = LineSearchRejected
  • 7 = LambdaTriesExhausted
  • 8 = MaxIterReached

message contains a short diagnostic string.


Using prebuilt binaries

Download the archive for your platform from Releases.

Each release contains:

  • Shared library

    • Windows: ballistic_solver.dll
    • Linux: libballistic_solver.so
    • macOS: libballistic_solver.dylib
  • C ABI header: ballistic_solver_c_api.h


C# / Unity usage

A C# P/Invoke example is available in:

examples/dotnet/

On Windows, place ballistic_solver.dll next to the executable (or ensure it is discoverable via PATH), then call ballistic_solve via DllImport.


Build from source

cmake -S . -B build
cmake --build build -j
ctest --test-dir build

The shared library target is ballistic_solver.


ABI notes

  • Plain C layout across the ABI boundary
  • Fixed-size arrays only
  • No dynamic allocation across the boundary

License

MIT License

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

ballistic_solver-0.3.2.tar.gz (19.9 kB view details)

Uploaded Source

Built Distributions

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

ballistic_solver-0.3.2-cp312-cp312-win_amd64.whl (104.4 kB view details)

Uploaded CPython 3.12Windows x86-64

ballistic_solver-0.3.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (119.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

ballistic_solver-0.3.2-cp312-cp312-macosx_10_13_universal2.whl (192.2 kB view details)

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

ballistic_solver-0.3.2-cp311-cp311-win_amd64.whl (103.3 kB view details)

Uploaded CPython 3.11Windows x86-64

ballistic_solver-0.3.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (116.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

ballistic_solver-0.3.2-cp311-cp311-macosx_10_9_universal2.whl (190.8 kB view details)

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

ballistic_solver-0.3.2-cp310-cp310-win_amd64.whl (102.6 kB view details)

Uploaded CPython 3.10Windows x86-64

ballistic_solver-0.3.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (115.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

ballistic_solver-0.3.2-cp310-cp310-macosx_10_9_universal2.whl (188.1 kB view details)

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

File details

Details for the file ballistic_solver-0.3.2.tar.gz.

File metadata

  • Download URL: ballistic_solver-0.3.2.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ballistic_solver-0.3.2.tar.gz
Algorithm Hash digest
SHA256 e6cda56c493d8b9ea96bf40477a1a9171cdc49ff10901b8da4220df9e9794d7c
MD5 8dbb49007b93bc886aed18fd7b2f4be3
BLAKE2b-256 94c7f16ade8f6cc3dbeae802dfe3d51bedf271ae83e7350f2dc0a48cc0efd4d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for ballistic_solver-0.3.2.tar.gz:

Publisher: release.yml on ujinf74/ballistic-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ballistic_solver-0.3.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for ballistic_solver-0.3.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4a64ab9b75344069118a893c89b13d7300b4ca5f4a60aceccd8ee7ea50f854a4
MD5 be0ee27ec33768c646dc6a4f9b3687a0
BLAKE2b-256 385f14ba0d65ca3045f1af649fa850bff7efa976fd0ba4fdf3bfea89b907e59a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ballistic_solver-0.3.2-cp312-cp312-win_amd64.whl:

Publisher: release.yml on ujinf74/ballistic-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ballistic_solver-0.3.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ballistic_solver-0.3.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c08434c0d5bacf4a98eba975f6d9aa4238039bf86dbea74aa94055f736c0e278
MD5 89180044d81837def809beee658e0ab6
BLAKE2b-256 24b0269fa1617d734cc2cf23903a04c917f1e79ca3f5d81d4db5f17d529315d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for ballistic_solver-0.3.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on ujinf74/ballistic-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ballistic_solver-0.3.2-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for ballistic_solver-0.3.2-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 1658d8c19437cf82cac347dbbd366b73b44308e2be8288499ab04e6fca2a5c47
MD5 8ee858c2bb0c3c6a47722552783dff55
BLAKE2b-256 4611c5fcdabba21473cd734cbeaf437033d48026bbc9d36f23c2a34680f768fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for ballistic_solver-0.3.2-cp312-cp312-macosx_10_13_universal2.whl:

Publisher: release.yml on ujinf74/ballistic-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ballistic_solver-0.3.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for ballistic_solver-0.3.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c55925e073faa78e02ffca38addd93b579f577c66c4a2c1d82a198c5d8514ccf
MD5 686b261f22dec467b5ca69498d22dc87
BLAKE2b-256 4f8b94c9910966b5fcc3df6b42dd23f5e6b92de1ae37ca598ad21506856b6c11

See more details on using hashes here.

Provenance

The following attestation bundles were made for ballistic_solver-0.3.2-cp311-cp311-win_amd64.whl:

Publisher: release.yml on ujinf74/ballistic-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ballistic_solver-0.3.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ballistic_solver-0.3.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 917e9bce05e70508bfd84539a853be8ea7902b898569f4be7e16e8b8436c2685
MD5 abd3ba06862129ccd6b3ae10302f0c06
BLAKE2b-256 e469416e537c2b328df480108ea2f9f1da99904525e0c41692189512a796fd89

See more details on using hashes here.

Provenance

The following attestation bundles were made for ballistic_solver-0.3.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on ujinf74/ballistic-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ballistic_solver-0.3.2-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ballistic_solver-0.3.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 dec99fbece6da748e506cbda295a8293770fedfcce6ffea777ef379e2fbd32dd
MD5 43089d667213da9300d5517f2714716b
BLAKE2b-256 ce0ff8e82cf70cd1b251a24237696915977a8b7e055d1f569c4e3c2aedce8d67

See more details on using hashes here.

Provenance

The following attestation bundles were made for ballistic_solver-0.3.2-cp311-cp311-macosx_10_9_universal2.whl:

Publisher: release.yml on ujinf74/ballistic-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ballistic_solver-0.3.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for ballistic_solver-0.3.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 25ea858c7af9181eea31f0d80fa5be45667636672e041a3a5238e4ee3757f805
MD5 69445c6a43d0cd312e32a7018a1df30c
BLAKE2b-256 9c8c74df5ee600232ee28753addba69f10fa63ce28b3c1a2cdc9c734cbc42deb

See more details on using hashes here.

Provenance

The following attestation bundles were made for ballistic_solver-0.3.2-cp310-cp310-win_amd64.whl:

Publisher: release.yml on ujinf74/ballistic-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ballistic_solver-0.3.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ballistic_solver-0.3.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 541b569d22beb772309b8661ee2545f8418d4c0487530ecdd83d74e4c94f883c
MD5 d724a82ca3a1dc775742b99dacc80fcf
BLAKE2b-256 99028dec6d1a96437e731e6c52f73f8a2bc844a0c639d52c6f842fd45b6a995c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ballistic_solver-0.3.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on ujinf74/ballistic-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ballistic_solver-0.3.2-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ballistic_solver-0.3.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 20220efb22c83faec97d4c789163d274895ff07257a596057a4ffd2d96b5dbed
MD5 147d5793b11ca76c7f71fbcb1a5839fa
BLAKE2b-256 4bbb149b8035ba22556130485117e47252c4d61c70b9a8dffa69d4ac6e3010a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for ballistic_solver-0.3.2-cp310-cp310-macosx_10_9_universal2.whl:

Publisher: release.yml on ujinf74/ballistic-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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