DEV Community

Patryk
Patryk

Posted on

Building a Ballistic Fire Control Simulator with Python, C# and Redis

description: How I built a real-time ballistic computer with Euler simulation, Coriolis effect, blast zones and a satellite map interface using microservices architecture.
tags: python, csharp, redis, opensource


Building a Ballistic Fire Control Simulator โ€” BALISTIC V5

A few weeks ago I started wondering: how hard would it be to simulate real external ballistics? Not just a simple parabola โ€” but actual physics with air resistance, wind, air density and even the Coriolis effect.

The result is BALISTIC V5 โ€” a full microservices ballistic fire control simulator.

๐Ÿ‘‰ GitHub: https://github.com/InsaneInfinity/Balistic


๐Ÿ—๏ธ Architecture

The system is split into two independent services communicating via Redis Streams:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     Redis Stream      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Python / Flask    โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ   โ”‚    C# Processor      โ”‚
โ”‚                     โ”‚   ballistics:stream   โ”‚                      โ”‚
โ”‚  - Leaflet Map      โ”‚                       โ”‚  - Euler Simulation  โ”‚
โ”‚  - Weather API      โ”‚ โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€   โ”‚  - Coriolis Effect   โ”‚
โ”‚  - Results Panel    โ”‚   ballistics:result   โ”‚  - Blast Zones       โ”‚
โ”‚  - PDF Export       โ”‚                       โ”‚                      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Enter fullscreen mode Exit fullscreen mode

Why Redis Streams instead of a simple key-value? Because every shot is an independent entry โ€” no data gets overwritten during sequential multi-target fire.


๐Ÿงฎ Physics Model

Trajectory Simulation

For kinetic energy rounds (APFSDS, HEAT) I use an Euler method simulation with dt=0.01s:

double v = Math.Sqrt(vx*vx + vy*vy);
double drag = 0.5 * cd * rho * area * v * v;
vx += -(drag/mass)*(vx/v)*dt;
vy += (-9.81 - (drag/mass)*(vy/v))*dt;
Enter fullscreen mode Exit fullscreen mode

For artillery rounds (HE, EXCALIBUR) I use an empirical angle formula based on the dist/max_range ratio โ€” artillery always prefers a high-arc trajectory (45ยฐโ€“65ยฐ).

Coriolis Effect

This was the most interesting part. The real deflection formula:

d_cor = ฮฉ ยท sin(ฯ†) ยท v_avg ยท tยฒ / 2
Enter fullscreen mode Exit fullscreen mode

Where:

  • ฮฉ = 7.2921ร—10โปโต rad/s โ€” Earth's angular velocity
  • ฯ† โ€” shooter's latitude (dynamic, updates with every position change)
  • v_avg = dist / tof โ€” average horizontal velocity during flight

Results for M107 HE at ~5km range, 54ยฐN latitude: ~3m deflection to the right โ€” matches NATO FM 6-40 tables.

Air Density

Calculated live from OpenWeatherMap data:

dens = (pressure * 100) / (287.058 * (temp + 273.15))
Enter fullscreen mode Exit fullscreen mode

๐Ÿ’ฅ Blast Zones

Based on NATO / FM 6-40 publicly available data:

Round Total destruction Heavy damage Light damage Hazard zone
M107 HE / EXCALIBUR 30 m 100 m 300 m 800 m
HE STD (RAK 120mm) 8 m 30 m 80 m 200 m
APFSDS kinetic only โ€” โ€” โ€”
HEAT โ€” โ€” โ€” 5 m

These render as 4 concentric circles on the satellite map with tooltips.


๐Ÿ”ซ Supported Systems

System Round vโ‚€ Trajectory
AHS KRAB (155mm) M107 HE 560 m/s Artillery arc
AHS KRAB (155mm) EXCALIBUR 560 m/s Artillery arc
M120 RAK (120mm) HE STD 280 m/s Artillery arc
M120 RAK (120mm) SMOKE 250 m/s Artillery arc
LEOPARD 2 (120mm) APFSDS 1650 m/s Flat
LEOPARD 2 (120mm) HEAT 1140 m/s Flat

โœจ Features

  • ๐Ÿ—บ๏ธ Satellite map with shooter/target positioning
  • ๐ŸŽฏ Multi-target selection โ€” mark multiple targets, fire sequentially
  • ๐Ÿ“Š Live results panel โ€” azimuth, elevation angle, TOF, wind drift + Coriolis
  • ๐Ÿ’ฅ 4-zone blast radius visualization
  • ๐Ÿ“„ PDF session report export
  • ๐Ÿ”„ Dynamic system/ammo switching without restart
  • ๐Ÿ” Session token authorization on all fire endpoints

๐Ÿš€ Key Lessons Learned

1. Euler simulation has limits
For high-velocity artillery (v0=827 m/s โ€” my initial wrong value!), the vacuum range formula gives unrealistic results. Real M107 HE has v0=560 m/s, not 827 m/s.

2. Bisection method for elevation angle
Finding the correct elevation angle for a given range required a bisection search. The tricky part: artillery prefers the high-arc solution (>45ยฐ), not the flat one.

3. Coriolis is smaller than you think
At 5km range with 20s flight time at 54ยฐN: only ~3m deflection. Significant for precision rounds like EXCALIBUR (CEP 10m), negligible for M107 HE (CEP 150m).

4. Redis Streams > Redis String for queues
Using XADD/XREAD with consumer groups means no data loss even if the C# processor is temporarily down โ€” messages wait in the stream.


โš ๏ธ Disclaimer

Educational and simulation purposes only. Real fire control systems use 6-DOF models, balloon sonde meteorological data, barrel wear corrections and dozens of other factors.

Full source: https://github.com/InsaneInfinity/Balistic

Would love to hear your thoughts โ€” especially on the physics model! ๐ŸŽฏ

Top comments (0)