Flight Simulator Guide (WIP)


Introduction

So you want to make a flight simulator? This article is about a commonly-used flight model and the physics behind it. I wish I knew this back when I made my previous 2D flight simulator projects. Please note that this article assumes you already have a high-school level knowledge of maths and/or physics (vectors especially are important) and little bit of knowledge in aircraft already.

Units

Aviation is a mess of different units. Just to name a few... Altitude is in feet, distance is in nautical miles, or feet, or kilometres, depending on where it is used. Speed is in knots, air pressure can be either inches of mercury or hectopascals. Just stick to metric/SI units for the physics. The maths is way simpler if you don't have to constantly convert units. Feel free to display the values to the user in whatever units you want though.

I need to specify something however. While my earlier flight simulators were metric, they had annoying conversions too because of the units I chose such as km/h for speed whilst distance and altitude was in metres. Instead, make sure everything uses the base units by themselves, e.g. second, metre, kilogram. Speed should be metres/second. Acceleration should be metres/second/second. Force should be in Newtons (which is kg*m/s/s).

Since realising all this, my scratch projects have solely used SI units internally.

Forces

There are 4 important forces acting on an aircraft: thrust, weight, drag, and lift.

Thrust is the force produced by the engines or whatever is propelling the aircraft. Weight is simply the force due to gravity and always pulls towards the earth. It is proportional to the aircraft's mass. Both drag and lift are related to each other. Drag is parallel to the airflow. Lift is perpendicular to the airflow.

It's up to you to decide how simple or complex you want your flight model as you could have just 4 vectors representing everything or you could split them up to model every single surface of the aircraft, although at that stage you might no longer be able to refer to drag and lift as abstract separate things as both are related to air pressure.

Microsoft Flight Simulator uses this:

The model I use in Flight Simulator 737 is actually pretty similar to this too, although squished into 2 dimensions.

Main loop

Ideally you would be using a main loop to constantly run the physics along with the rest of the simulator. It needs time-keeping of some kind to ensure the physics runs at the correct speed (remember that the physics is measuring time in the base unit of seconds, not cycles of a loop). You could use delta-timing.

Physics tick

Every tick the following needs to happen...

1. All the forces currently acting on the aircraft are found.
2. The forces are added together to form a single resultant force and couple.
3. Acceleration to the aircraft is found from the resultant force (both positional and angular), taking into account the total mass of the object. (a=F/m, or acceleration=force/mass)
4. Acceleration changes the velocity (in pseudocode: velocity += acceleration/time_elapsed).
5. Velocity changes the position and angle (in pseudocode: position += velocity/time_elapsed).

You may want to refer to this project which uses the same steps but not for an aircraft: Free Body Physics Simulation

When a force is applied to a free object at a point that isn't at its center of mass, it will cause it to both translate and rotate. Translation is easy, it's identical to applying the same force at the center of mass. Rotation can be treated as a couple which are 2 vectors which make a pure rotational force ("torque"). They need to be separate so that the aircraft's translational and rotational components can be handled.

It is basically like this...

TranslationRotation
massangular mass (or "moment of inertia")
forcetorque (or "moment of force")
accelerationangular acceleration
velocityangular velocity
displacement (or "position")angle (or "direction")

It can be confusing as there are a bunch of words which refer to the same concept. The above table is not exhaustive, there are many more!

Lift and Drag


Wikipedia article on lift


Wikipedia article on drag

Lift is the force acting on an object in an airflow (or fluid in general) that is perpendicular to it. Drag is parallel. They are both related to each other and as you can see from the above equations, they are the same (but with different variable names). Generally both are proportional to surface area, air density, velocity squared, and the dimensionless coefficient to account for the shape of the object.

With lift you want the surface area that is parallel to the airflow, and for drag you want the surface area that is perpendicular. You need to account for the fact that the aircraft is usually not travelling in the same direction as the airflow, for example it might be slightly pitched up. The wings themselves may be pitched too.

The coefficients need to be found in some way. It's more complicated because they need to account for the shape of the object and anything else not covered by the other parts of the formulas. It also varies depending on the airflow direction. You can find coefficients for airfoils online but the rest may have to be guessed or found experimentally using CFD or physical models in wind tunnels.