https://github.com/sunsided/ballistics
A Kalman filter ballistic curve estimation playground
https://github.com/sunsided/ballistics
ballistic-curve kalman-filter monte-carlo-sampling rust simulation
Last synced: 11 days ago
JSON representation
A Kalman filter ballistic curve estimation playground
- Host: GitHub
- URL: https://github.com/sunsided/ballistics
- Owner: sunsided
- Created: 2024-06-08T17:27:15.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2026-05-04T20:35:05.000Z (about 2 months ago)
- Last Synced: 2026-05-04T22:26:14.652Z (about 2 months ago)
- Topics: ballistic-curve, kalman-filter, monte-carlo-sampling, rust, simulation
- Language: Rust
- Homepage:
- Size: 211 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Agents: AGENTS.md
Awesome Lists containing this project
README
# Ballistics Estimation
[](https://github.com/sunsided/ballistics/actions/workflows/ci.yml)
[](https://github.com/sunsided/ballistics)
A small Rust/ggez playground that tracks a wind-perturbed projectile with a Kalman filter and predicts its impact zone on the ground via Monte-Carlo sampling of the filter's covariance. Acts as a testing ground for the [minikalman](https://github.com/sunsided/minikalman-rs) crate.

*Blue = true firing trajectory (gravity only), Green = filter-predicted trajectory, Cyan dot + ellipse = state estimate with 1σ covariance, Orange bar + whiskers = predicted impact zone (±2σ with min/max).*
## What it does
- An opponent on the right edge fires projectiles with a random launch angle drawn from Normal(60°, 10°) clamped to 25°–80° and a speed of 100–120 m/s.
- Gravity (-9.81 m/s²) and a time-correlated wind model (sinusoidal base plus Ornstein–Uhlenbeck-style correlated noise on the x-axis) perturb the flight.
- The observer receives noisy 2D position measurements each physics tick (uniform noise in ±5 px per axis).
- A 6-state linear Kalman filter with state vector `[x, y, vx, vy, ax, ay]` (constant-acceleration model, dt-based state transition) is built on `minikalman`; the measurement matrix observes position only.
- Impact prediction runs 64 Monte-Carlo rollouts per update on a background thread: it Cholesky-decomposes the 4×4 position/velocity sub-covariance, draws Gaussian samples, propagates each sample until it crosses the ground (with a quadratic root-solve for the exact crossing time), and aggregates mean, std-dev, min, and max of the landing x to draw the impact zone.
- Game time is accelerated by `GAME_TIME_FACTOR = 10.0` at `PHYSICS_FPS = 60` for faster iteration.
## Running it
```bash
cargo run --release
```
The `resources/` directory containing `LiberationMono-Regular.ttf` must be present, as `main.rs` adds it as a resource path for text rendering. The font is stored via [Git LFS](https://git-lfs.com/); make sure Git LFS is installed (`git lfs install`) before cloning, or run `git lfs pull` after cloning.
## Ideas
- Can we estimate the mass of the projectile as well?
- Both the mass and the initial firing force determine the acceleration.
- The mass will affect the curvature of the trajectory.
## License
Licensed under the [European Union Public Licence v1.2 (EUPL-1.2)](https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12).