← Back to Projects
Simulation · Java

AirSim2D.

A custom-built vector-based flight simulator that treats the aircraft as a real rigid body — complete with angle of attack, lift and drag curves, thrust vectoring, and a Fly-By-Wire computer that holds trim without pilot input.

*Requires Java 11+

Java Physics Engine Aerodynamics Fly-By-Wire
AirSim2D project cover art
Flight Model

The math behind the aircraft.

AirSim2D runs the aircraft as a real 3-DOF rigid body, with physics stepping at 200 updates per second and rendering kept separate. Each step recomputes angle of attack, dynamic pressure, wing and tail lift, drag, thrust, gravity, and the pitching moment about the centre of gravity.

Model component
Rigid-body core

3-DOF equations of motion

The simulator advances a rigid body in planar translation and pitch. In code that means altitude, velocity, pitch angle, and pitch rate are updated every physics step, while the Swing render loop stays separate.

\[\sum \mathbf{F} = m\mathbf{a}, \qquad \sum M_{cg} = I_{zz}\dot{\omega}\]
\[\mathbf{s} = [x,\ y,\ \theta,\ v_x,\ v_y,\ \omega], \qquad dt = \frac{1}{200}\ \mathrm{s}\]
Code constants: m = 70000 kgIzz = 8.0 x 106 kg m2

These equations are rendered with LaTeX on the page, but the constants and relationships are taken directly from the Java flight-model code.

Deep Dive

Built like a miniature flight lab.

At the core of AirSim2D is a frame-by-frame rigid-body simulation loop. Every update step resolves thrust, lift, drag, and weight into world-space force vectors, sums the moments around the center of mass, and integrates the aircraft state into new linear and angular velocities. That means pitch attitude, angle of attack, and airspeed all feed back into one another instead of being faked with arcade-style shortcuts.

The Fly-By-Wire layer sits above that physics loop as a small control computer. It constantly measures pitch deviation from the desired trimmed attitude and nudges elevator deflection to counter drift, which effectively gives the aircraft an auto-trim brain. That stabilizing feedback makes sustained level flight possible without continuous player input and turned the simulator from a tech demo into something that feels genuinely flyable.

The hardest part was embracing the ugly edges of aerodynamics instead of smoothing them away. Stall behavior had to appear as a non-linear break in the lift curve, low-speed conditions needed extra care to stay numerically stable, and the whole rendering stack had to be built directly in Java Swing without leaning on a game engine. The result taught me as much about engineering tradeoffs as it did about graphics and controls.

Cockpit

How you fly it.

The simulator starts in stable cruise, then hands you a small set of direct controls for thrust, elevator input, trim, and recovery.

Input
Action
Mouse drag Throttle slider
Engine thrust from 0% to 100%.
Up / Down arrows
Elevator deflection up to plus or minus 25 degrees, with auto-trim disengaging on manual input.
W / S
Direct pitch override.
Auto Trim button
Toggles the trim computer on or off.
Enter
Resets the aircraft after a stall.
Initial state

The simulation starts trimmed in level flight at 10 000 m and 258.7 m/s, with auto-trim off.

Planned Features

Where I would take it next.

The core rigid-body model is already there, so the next steps are mostly about making the aircraft feel more faithful at the controls and more complete across the full flight envelope.

Yoke simulation

Replace the direct pitch override with proper elevator actuation so pitch changes come from aerodynamic moments instead of hardcoded angle jumps.

High-lift devices

Add flaps and slats that shift the lift and drag curves, making low-speed flight and approach handling more realistic.

Engine inertia

Model turbofan spool-up and spool-down delay, plus the pitching moment introduced by engines mounted below the wing.

IAS vs TAS

Compute indicated airspeed from dynamic pressure so the HUD reflects cockpit-style instrument behavior instead of true airspeed alone.

Transonic drag rise

Add wave-drag onset near Mach 0.78 so the aircraft picks up the right performance penalties in the transonic regime.

Ground mechanics

Introduce landing gear, rolling friction, and braking force so takeoff and landing phases are simulated instead of skipped.