C/C++ core · Stable C ABI · Python/PyPI · Unity/C#

ballistic-solver is a deployable intercept solver for moving targets under gravity and quadratic drag, with optional wind. Instead of assuming a closed-form ballistic arc, it simulates projectile motion and solves the intercept numerically.

Problem

I wanted a solver that still works when the projectile path is strongly curved by drag and the target is moving. That rules out simple vacuum-style closed forms as the main solution path.

Why Numerical Instead Of Closed-Form

  • Projectile dynamics include quadratic drag, optional wind, and fixed-step RK4 integration.
  • The hit condition is solved against a moving target, with an extended API for constant-acceleration targets.
  • The solver returns explicit status codes, diagnostic messages, and the best result found even when convergence is imperfect.

Architecture

Inputsrelative target motion, speed, drag, solver params
SimulationRK4 projectile integration with drag and wind
Residualclosest-approach miss expressed in launch-angle space
SolveLevenberg-Marquardt + line search + Broyden-style Jacobian refinement
DeployC ABI, Python package, Unity/C# interop

What I Built

  • Header-only C++ core focused on solver logic rather than app-specific wrappers.
  • Stable C ABI with plain-C data layout and fixed-size arrays for FFI-safe integration.
  • Python package with presets, utility helpers, and prebuilt binaries through PyPI.
  • Unity/C# path using P/Invoke so the same native solver can be used in game/runtime contexts.
  • Failure handling through explicit status codes such as invalid input, Jacobian failure, line-search rejection, and max-iteration exhaustion.

What This Project Proves

  • Mathematical modeling: I can translate a nonlinear physical intercept problem into a solver with explicit assumptions.
  • Numerical-method judgment: I can combine integration, residual design, damping, line search, and Jacobian updates into one practical method.
  • Deployable engineering: I can expose the same core through C ABI, Python, and Unity/C# instead of leaving it as lab-only code.
  • Debuggability: explicit statuses and best-effort outputs matter to me as much as nominal success cases.

Verified Results

From the repository README benchmark on a local Windows release build over 500 generated linear-target cases:

Preset Median Solve Time p95 Solve Time p95 Miss
fast 0.107 ms 0.233 ms 3.399e-02 m
balanced 0.219 ms 0.492 ms 7.287e-03 m
precise 0.265 ms 0.583 ms 7.655e-06 m

Limits And Failure Cases

  • The runtime using the solver must match the same physics and integration assumptions; different timesteps or integrators can invalidate the hit.
  • Strongly nonlinear cases are handled numerically, so convergence quality depends on solver settings and problem conditioning.
  • This project prioritizes deployable robustness and explicit diagnostics rather than pretending every case has a perfect analytic solution.