# Simple aircraft physics question

This topic is 3549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am working on a basic aircraft simulation but have hit a problem. I can calculate the forces on the plane at a time (lift, weight, thrust, drag) which when added together give me an acceleration vector of the plane. Now what's the best way to use that acceleration vector to compute a velocity? I started using an accumulated vector for the velocity but that isn't working out very well. Basically every frame I was calculating the acceleration, adding to velocity vector and then adding the velocity to the position.
vector3 acceleration = CalculateAccelVector();
velocity += acceleration;
position += velocity;
This was causing a few issues. For example if the aircraft was moving along the z-axis and made a quick turn to the x-axis, it would maintain its velocity along the z-axis because there was no force to cancel it out. I've tried dividing the velocity vector every frame by some amount so that eventually the extra force would be cancelled out and fudging the velocity direction toward the thrust direction but haven't found good values for this yet. The aircraft would either act like a very powerful rocket with no drag (not losing any speed in turns) or the heading would take too long to match the thrust direction (flying forward and sideways). I think I am missing something simple here but don't know what, any ideas? Not sure if it matters but the flight model I am trying to implement is not a full blown simulator. Much simpler inputs to the physics simulation. Thanks

##### Share on other sites
It sounds like you are missing friction completely - are you sure your drag calculations are correct?

##### Share on other sites
The basic physics equation that should be burned into your memory is Newton's second law. Commonly, this is written as:

F = m * a

where F is the net force on the object, m is the object's mass, and a is the resulting acceleration of the object. The more accurate form - and the one you will want to use for modeling - is:

F = d/dt (m*v) = m * dv/dt

where d/dt is the time rate-of-change of the quantity in parentheses, and v is the velocity of the object. For small, discrete steps in time, and for error calculations, dv/dt in the final term can be translated as, "the difference in velocity divided by the difference in time".

At a given moment (frame or cycle) in your simulator, you know F (the sum of the forces). In all likelihood, you know m (the mass of the object). You want to know the difference in velocity, dv, so the only thing left for you to calculate is dt, the change in time since you last updated the forces and velocity. (I am assuming you are checking forces and updating velocity in the same frame; things can be a bit more tricky if you are not.) If you have a framerate subroutine already running, you already have dt available somewhere in your program. If not, see the next paragraph.

To calculate time elapsed since the last frame, you need to start a clock. The quantity dt will be the difference in this clock's value between the current and previous frame. There are many, many ways to keep track of time. For a simple simulator, I would recommend the ubiquitous 'ctime.h' library - standardized, well-documented, very simple to use. For more sophisticated simulations where small variations in your timestep can make your DE unstable, a more accurate approach may be needed.

Once you have dt, solving the equation for dv gives you:

dv = F * dt / m

To update your velocity, simply add dv to your previous velocity. Note that this works just as well in three dimensions (with vector equations), since v and F are vectors while m and dt are scalars. Simply do the above calculation for each axis.

On a nearly-irrelevant tangent, I'd be very interested to see your equations of flight. In particular, how are you simulating lift and drag?

Good luck!

##### Share on other sites
HI . I think your problem lies in that you are missing the air-resistance alltogether.

first thing ,you must know the RELATIVE AIRSPEED of the airplane .

hkVector4 RelAirSpeed

RelAirSpeed.z=hkRigidBody->GetLinearVelocity().Dot3( AirplanelocalVector( 2 ))
RelAirSpeed.y=hkRigidBody->GetLinearVelocity().Dot3( AirplanelocalVector( 1 ))
RelAirSpeed.x=hkRigidBody->GetLinearVelocity().Dot3( AirplanelocalVector( 0 ))

=please note that RelAirSpeed.z is the INDICATED airspeed that you should use for all your lift equations / dashboard airspeed readout , etc )

WITH the RELAVITE airspeed to the aircraft ,you should have a matrix (or at least a 3-dimensional value /vectors ect ) expressing how "resistant" to the air speed is the aircraft in each of the axis .

very obviously this would be something like hkVector4 AirResstance( 10.0, 900.0 , 2.0f ) , 0 ) , meaning that an aircraft generates 2 (whatever units of force ) to the wind coming in Z-axis (i.e. fliying normally ) but generatoes 900 when the same airspeed is caming trhought the Y-Axis . etc..etc...

this way .. even that you aircraft changes attitude while still moving mainly in the Y axis , It will definintely slow down and start moving in tthe desired direction .

Cheers
Javier

##### Share on other sites
Quote:
 Original post by swiftcoderIt sounds like you are missing friction completely - are you sure your drag calculations are correct?
I did find a problem in there. Should have been taking the absolute value of something that I wasn't. Not the main issue but it would have been down the line.

Quote:
 Original post by TythosEternalThe basic physics equation that should be burned into your memory is Newton's second law. Commonly, this is written as:F = m * a...
That was the issue, my implementation of it was wrong. It is looking much better now, not perfect but much better. Probably have to play with my force calculations a bit.

Quote:
 Original post by TythosEternalOn a nearly-irrelevant tangent, I'd be very interested to see your equations of flight. In particular, how are you simulating lift and drag?
My implementations of those are very basic.

The drag calculation is split into drag due to speed and drag due to aoa.

To calculate drag due to speed, I take the current speed over the maximum speed (constant). At maximum speed this factor would be 1.0 to counteract the thrust.

To calculate drag due to aoa, I take the current aoa over a max drag aoa (constant). At higher aoa's (absolute value) more drag will be generated.

The final drag factor is then those two added together and multiplied with the max thrust. At max velocity the drag factor should counteract the thrust force and the velocity shouldn't increase due to thrust.

Lift is a bit more complex, my implementation might be wrong (lots of hard coded constants currently) but it is producing the desired results at the moment.

Like drag I split the lift calculation into lift due to speed and lift due to aoa.

To calculate lift due to speed, I take the current speed over a minimum speed (stall speed) and clamp it to a max value (constant). This will hopefully allow me to simulate takeoffs/landings in the future. The value needs to be clamped otherwise too much lift gets generated at high speeds.

Almost the same for the lift due to aoa, I take the current aoa over a maximum lift aoa (less lift is generated if the aoa gets too high) and clamp the value to a min and max (more constants).

Those two factors are then combined, clampled to a min and max (even more constants) and then multiplied by the aircrafts mass and gravity.

Quote:
 Original post by jcarrionHI . I think your problem lies in that you are missing the air-resistance alltogether. ...
Why is the air resistance a 3 component vector, shouldn't it just be a scalar constant?

What's the best way of implementing this? Taking the difference between the direction of the aircrafts nose and direction of velocity and adding an air resistance drag force to the total acceleration?

Thanks

##### Share on other sites
>>Why is the air resistance a 3 component vector, shouldn't it just be a scalar >>constant?

because the aircraft is not spherical. It is much more aerodynamic in his longitudinal (z) axis than any other axis . Correct values are -around-

x = 9
y= (100 .. 900 )
z = 2

multiply with the constant of choice to get meaningfull values.

Indeed , you soon realize that the aerodynamics of an aircraft are best defined by a 3x3 matrix . but that's probbably too much for the time being .

cheers
j

##### Share on other sites
For the lifting surfaces
------------------------
Lift: L = (CL)(1/2)(rho)(V^2)(S) or L = (CL)(q)(S)
Drag: D = (CD)(1/2)(rho)(V^2)(S) or D = (CD)(q)(S)

Where:
CL = coefficient of lift (varies with angle of attack)
CD = coefficient of drag (varies with angle of attack)
rho = density of fluid (air)
V = velocity of free-stream air
S = wing planform area
q = expressed as "dynamic pressure", is equal to (1/2)(rho)(V^2)

If air density and planform area are assumed constant, lift and drag of an airfoil varies with the angle of attack and by the square of the TRUE airspeed (not indicated airspeed).

By the way, in this case CD should be used to express total drag (that is induced + parasite drag).

Lift acts perpendicular to the relative wind (velocity vector) and drag acts parallel and opposite to velocity. Lift and drag are components of a single resultant force.

This should give you enough information to get your google on, or maybe to start a chain reaction of wikipedia searches. If you implement your flight model based on even a simple shred of authenticity, you will get much better results than trying to fudge it like you are and others here have suggested you do.

Also... you should not be using an Euler integrator. Use "Improved Euler" or RK4 for better stability.

##### Share on other sites
Quote:
 Original post by jcarrionIndeed , you soon realize that the aerodynamics of an aircraft are best defined by a 3x3 matrix

How do you figure, sports fan?

##### Share on other sites
I'd imagine because you need to represent a complete 3 dimensional friction model. Wind resistance is approximated from the cross section of the aircraft in the direction of the wind. You could use a matrix to transform the wind vector into a resistance vector, based on the world space version of your 3x3 resistance transformation.

##### Share on other sites
Quote:
 Original post by bzroomI'd imagine because you need to represent a complete 3 dimensional friction model. Wind resistance is approximated from the cross section of the aircraft in the direction of the wind. You could use a matrix to transform the wind vector into a resistance vector, based on the world space version of your 3x3 resistance transformation.

Oh sorry for the confusion, I wasn't disputing the fact that the matrix would work as a hack, only because the OP says "the flight model I am trying to implement is not a full blown simulator. Much simpler inputs to the physics simulation" (it would not work for a realistic flight simulator)... I was disputing the statement "aerodynamics of an aircraft are best defined by a 3x3 matrix" which is absolute nonsense.

One could always do some reading

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632993
• Total Posts
3009763
• ### Who's Online (See full list)

There are no registered users currently online

×