# How to calculate altitude in a flight simulation?

I guess altitude from sea level in the real aircraft is read from barometer, while for the altitude from ground a radar is used. For the purposes of very simple simulation, and assuming aircraft is on ground at certain airport at certain altitude.

The starting variables are then nothing but a throttle position, which over time increases, which translates into speed. And once the aircraft is airborne also the pitch. For this purpose I would not assume any roll, wind or other factors. The aircraft engine has certain torque % and pilot pulls the nose up to achieve certain pitch.

Is it possible to get the altitude simply as the function of pitch and torque % Or to put it differently what are the minimum variables to take into account to come up with an altitude?

UPDATE

Obviously there's something wrong with the question because it resulted in the explosion of complexity, even touching the topic of atmospheric re-entry.

What I want to know is, as a pilot of a simple simulator, standing still on the runway, I can only change two things.

1. Throttle, and some time later
2. Pitch

I don't have to do anything else whatsoever in simple sims, I click on + to set the throttle to X, and when the speed is Y, I pull the nose up, and now the altitude keeps on picking up. How do those two changes to those two variables (throttle, pitch) eventually give me the altitude and speed, through a series of equations (that needn't be neither simple nor linear)?

• Ska - what are you using to turn torque into thrust? Engine efficiency, drag etc all are needed. There is no simple model for this. Dec 11 '17 at 9:41
– Ska
Dec 11 '17 at 9:50
• You might want to have a look at chapter 5 of Flight Dynamics in Microsoft Flight Simulator on FS Developer. The model is quite complex for your need, but still a simplified approach.
– mins
Dec 11 '17 at 9:55
• A simpler method with a certain degree of realism is from the power curve, I've updated my answer. Dec 12 '17 at 10:36
• I see that and roughly understand it. I still don't see how that translates to my keyboard +/- (throttle), and keyUp/keyDown for pitch. Because these are the only things I can change. Should I be able to infer that from your answer?
– Ska
Dec 12 '17 at 10:48

You can't directly calculate the altitude of an aircraft from any set of control settings. The altitude is dependent on the history of the aircraft. For example:

• Fly level at full power for one minute, and pitch up suddenly. You will be near the ground, having quite some speed.
• Climb at full power for a minute. You will be at high altitude, going quite slow.

In both situations, your aircraft is pitched up and at full power, but at very different altitudes. So, what are then the minimum variables needed?

This answer is quite difficult to give. If you're making a professional simulator, thousands. If you're making a platform game, just pitch and power, as well as some way of knowing the history of the aircraft. Usually, this is just a stepped simulation: at each moment in time, determine what your current pitch and power do to the attitude and altitude of the aircraft, and save it for the next time step. Of course, you need some model for relating these variables to actual accelerations of your airplane, and again, this model can be as complicated as you want or need it to be. See Koyovis' answer for more details on such a model.

• Not the real sim but also slightly more complex than a platformer. History, as I mentioned in the question is aircraft on ground, then throttle is set to say 70%, then wait, then pitch up. Now how is my altitude changing?
– Ska
Dec 11 '17 at 8:56
• @Ska Again, there's no easy answer. You can only calculate climb rate if you assume steady state: we have pitched up, and waited for the aircraft to settle at a certain speed. Think about driving a car. You press the accelerator to 70%, now what is your speed? You don't know. You can only calculate the final speed. To get the position as a function of time, you need to iteratively see how much the car is accelerating at each moment in time. Dec 11 '17 at 10:29
• @Ska If you don't know how to calculate a trajectory in space as a function of forces, this question may help you along (you will probably want to do Euler integration) Dec 11 '17 at 10:30
• @mins Exactly (although the scene has quite a few inaccuracies: Euler's method is numerical as opposed to analytical, not theoretical; there's no such thing as a parabolic orbit, to name a few) Dec 11 '17 at 14:25
• (well, there is a parabolic escape trajectory, but this is supposed to be about reentry; as far as I know, no human has reached Earth's escape velocity). Dec 11 '17 at 14:37

Newton has worked out for us that every movement is the result of a force, or a balance of forces. The minimum requirement is to have a force model of lift - weight - drag - thrust.

With a fixed wing aircraft, the forces are a function of:

• Thrust
• Aircraft speed Aircraft configuration (high lift devices etc.)
• Aircraft attitude in 6 Degrees of Freedom: fwd/aft, left/right, up/down, pitch, roll, yaw. Both relative to gravity and to free airstream.
• Flight path

Once all the forces are known, work out the equations and direction of motion as a result of the forces, as a function of time.

All in all not a simple model. You would be able to find the force equations and the flight dynamics in open source software such as FlightGear. One has to adhere to the open source license of course, but one could read the source code to understand what the equations are. These are computed every so often per second, and parameters updated for the next clock tick.

Another possibility, a bit more straightforward, is to consider the energy balance of the aircraft. Engine power or thrust setting is what moves the aircraft, and flight starts with thrust as a function of speed. This energy is converted into increase/decrease of kinetic energy, or increase/decrease in potential energy.

You would still have to know weight, attitude relative to free stream etc, but would now compute vertical lift power (weight * climb speed) and horizontal aerodynamic drag power ( a constant * speed$^3$).

• this question which is about excess lift and power for climbing,
• this answer on how to compute aerodynamic constants, then flight characteristics per time step
• this answer for torque vs thrust for a helicopter rotor.

EDIT

The above is of course a bit complicated due to the many forces acting, and the fluid dynamic nature of the forces. The second method briefly mentioned above is much simpler: use the aircraft performance curve.

• Power required is a curve, determined by aerodynamic factors and weight.
• Power available can be modelled as a straight line, for simplicity's sake.
• Increase throttle, and power available goes up/down.
• The intersection point between Power available and Required is the airspeed at which the aircraft settles in trimmed flight.
• Vertical distance between available and required can be used for climb. Airspeed will then reduce.
• The right hand side of Power Required, after Minimum Power Airspeed, is roughly proportional to $V^3$. You could only model this bit for simplicity sake.
• Climbing will use up power roughly according $P_{climb} = m \cdot g \cdot c$, with c = climbing speed in [m/s], m = mass in [kg]
• Aircraft nose-up pitch is a linear function of climbing power available (simplicity!)

You can see that the airspeed will need to be high enough for the aircraft not to stall.

Inputs change all the time (your power setting and stick pitch), resulting in a new Power Available line and climbing power demand. The response to the new requirements is not instantaneous of course, but slowly creeps to the new equilibrium. How fast or slow can be regulated with a software gain factor.

So with $\delta_{throw}$ the throttle deflection, $\delta_{pitch}$ the stick pitch, and $c$ the climb speed:

$$P_a = k \cdot \delta_{throt} \tag{1}$$

$$c = \delta_{pitch} \tag{2}$$

$$P_r = f(m, V^3) + m \cdot g \cdot c \tag{3}$$

On the runway, throttle setting = power = $m \cdot a \cdot V$

• Is thrust == torque? I do know the weight. How do I get drag?
– Ska
Dec 11 '17 at 8:59
• No, torque is the force moment you need to rotate the propeller, there's a graph in this answer. You get drag by multiplying a constant times speed$^2$, the constant changes with air density and pitch attitude. There's a sort of an explanation here. For power considerations you would multiply drag * airspeed. Dec 11 '17 at 9:08
• Interesting. So to get the thrust I also need altitude (air density), and to get the altitude I need the thrust :) Isn't this leading to cyclic reference?
– Ska
Dec 11 '17 at 9:20
• Not if you compute the equations iteratively, and use the data of the previous timestep to compute the data in the new tilmestep. So new velocity is old velocity plus (time interval * acceleration) Dec 11 '17 at 9:30
• >> apply throttle, which applies thrust, which accelerates the aircraft, and speed picks up.<< So now we have the speed which we use in the rest of the equations you mentioned? >>Torque = f(throttle, air density), drag = f(air density, speed squared, pitch), lift = f(air density, speed squared, pitch, flight path angle); <<
– Ska
Dec 11 '17 at 12:18

Since I have created my own (over)simplified simulator I think I have some authority to answer.

Let's start with the basics, your question is quite broad, if you could mention the purpose of the simulator it would help narrowing the scope down.

Furthermore you say you want a simple simulation but you've stressed pitch. Now you have to calculate:

• from the pitch the angle of attack,
• from the angle of attack deduce the $C_L$ (coefficient of lift)
• from that deduce lift and then subtract the weight
• then calculate from the excess lift (if any) the du/dt (ie acceleration)
• from acceleration get the current vertical speed and finally
• calculate the vertical displacement and consequently your new altitude.

Unfortunately that's not in the realm of simple. Of course it depends on how one could define simplicity.

I would strongly suggest you have a look at BADA and total energy model. They have done some of the dirty work but beware: BADA is not for free, it's not even paid. Only Eurocontrol member countries can use it. That leaves you with the mathematics model (which is not bad) but without any data. That means you don't know:

1. Aircraft engine so you don't know T.
2. $C_L$ so you can't calculate lift for a particular aircraft
3. $C_D$ so you can't calculate drag for a particular aircraft
4. Aircraft weights so you can't calculate W

For the explanations of the symbols I will shamelessly point you to Koyovis' answer

One might argue that 1 and 4 can be found publicly. But then there is $C_L$ and $C_D$. And one thing that I've learned the hard way, is that coefficients cannot be calculated. At least not easily and accurately. Otherwise there wouldn't be any wind tunnels by today. BADA uses predefined $C_L$ and $C_D$ for each aircraft for different configurations. They don't include coefficient calculation in their model. That says a lot to me.

If you embark on that type of calculations then you are way off what you called simplified simulator. If you decide to do it though, again Koyovis' answer has links to useful questions and answers that I don't want to repeat here.

You can find BADA manual here, at least that seems to be publicly available so I guess (and this is a disclaimer, I'm not a lawyer so this isn't legal advise) you can use the mathematical formulas described in there.

The concept is in general that you have 3 variables, thrust, speed and rate of climb or descent. In each iteration of calculations you specify 2 of them, and then you calculate the 3rd from the equations. The equations though make it a bit more tricky than I made it sound.

• You linked to a BADA 3 document. BADA 4 has more fundamental calculations. I doubt one could easily get access to the necessary data for an actual aircraft type, but for the purpose of an exercise like this perhaps one could get some airfoil polar graphs and ignore the effects of the fuselage and so forth. Dec 30 '17 at 22:43
• @DavidK BADA 4 is not accessible unless you build a real aircraft simulator or something similar and you can convince Eurocontrol that you need 4 and not 3. OP needs nothing of the above. He simply asked the wrong question at the wrong place. Dec 31 '17 at 13:30
• The information about BADA 3 is useful; I just wanted to clarify that the limitations described above don't apply to all of EUROCONTROL's products. (And this is only for the sake of other people who might see this answer; I agree that the chance of getting any BADA 4 data for OP's purpose is practically nil.) Dec 31 '17 at 13:45

There are a number of control inputs that are put in to get the aircraft climbing at a certain angle, or descending at a certain angle. If you know the airspeed of the aircraft in feet per second, you should be able to use trigonometry to calculate of that speed how much is horizonatal and how much vertical. The vertical component can then be used to adjust the altitude and the horizontal the position over the ground.

So you must constantly calculate altitude based on if the aircraft is climbing or descending just as you calculate position over the ground constantly as well.

I don't know how to translate control movements into trajectories, this would be dependent on speed again, for example at slower speeds you move the controls quite a long way to achieve a desired pitch angle where at higher speeds the controls are much more "firmer" and responsive.

Now add a bit of bank, or air currents, different aircraft, or the fact that real aircraft never quite fly straight and level, they move around a little, ever so slightly speeding up and slowing down, and it makes you realise why it would take a team of maybe a dozen some months if not years to produce something like Microsoft Flight Sim.

Even a simple model is complicated. Much easier to know how to fly an aeroplane than know how to write a simulator!

Hope this answer helps in some way. I don't wish to appear negative. Good luck!

• As I stated in the question, I'm not trying to do full sim. Just a simplified model.
– Ska
Dec 11 '17 at 8:57
• The key question you really have to answer yourself is how to simplyfy it? The point I was making was that altitutide and position over ground is related to speed and climb angle, and if you have these as key things you "know" then the simplification could come from how to get from torque, pitch etc, to speed and climb angle. Dec 12 '17 at 7:48
• You can check my update in the question if that makes more sense.
– Ska
Dec 12 '17 at 10:03