Jump to content

Equation for air resistance as a function of altitude and velocity.


Recommended Posts

I'm writing an autopilot script in KOS and I need to account for air resistance. I believe it should be proportional to the cross sectional area and the square of the velocity and I'm guessing it's inversely proportional to the altitude (or maybe the square of the altitude). Is this right, have I forgotten anything, and do you know what the constants I should be using are?

Thanks.

- - - Updated - - -

Oh and I guess there's drag coefficients on the parts. Where do they come in? Do they represent the area?

Link to comment
Share on other sites

The current aerodynamics model in stock KSP is not a realistic representation of the way aerodynamics really work, so looking up references to real world aerodynamics will not help you in KSP. It might be worth bearing in mind that the aerodynamics model is being entirely changed for 1.0, so if you are planning on putting a lot of effort into getting your script right, you might be better off waiting until after the change.

My understanding of how KSP models drag now has the drag force on a part proportional to the mass rather than cross sectional area and linearly with velocity rather than as the square of velocity. I'm not sure how the atmospheric density profile is represented, though.

In the real world, aerodynamics is a deeply complex subject that can't really be summed up in a simple forum post. The temperature/pressure/density profile obviously varies with weather, but is modelled in a number of ways, for example the International Standard Atmosphere, but I would not be surprised if the KSP atmosphere is not at all representative of the real atmosphere.

Link to comment
Share on other sites

I have a formula that seems pretty accurate, but it's buried deep within a spreadsheet I don't have easy access to on this tablet. As I understand it, KSP drag does go up with velocity squared (it's lift from wings that is currently proportional to velocity, at least until v1.0) but the atmospheric pressure is somewhat unrealistic. It can be worked out from information in the wiki.

I can find the details next time I'm on my PC if that would help.

Link to comment
Share on other sites

I'm your guy.

KSP uses the standard viscous drag equation for it's drag calculations, the equation is:

Zp1Fcpb.png

Where oB0IGCV.png is the atmospheric density, 7BpUrQa.png is the cross section area, and W79ymTh.png is the drag coefficient. For KSP, 7BpUrQa.png is simplified to eY4BOFf.png (18tCwGn.png being the mass of the part), and W79ymTh.png becomes zO3QEBj.png, the drag coefficient of the part, and the atmospheric density becomes zdgdOhq.png (where MEDkyCP.png is the atmospheric pressure). Overall, it gives you this:

g26UjOx.png

Source: I dealt with this way too much for RealChute.

I'll LaTeX this in a few mins for clarity.

EDIT: Done

Just to be clear, this is only good for stock KSP pre 1.0. No idea what it'll look like post 1.0, and FAR does not follow this at all.

Edited by stupid_chris
Link to comment
Share on other sites

That would be great, thanks. :D

I'm using the current aerodynamics model for two reasons. This is for a university programming project as well as for myself, and it may be due in before the update, and also I wanted to learn how to make it work with the simple aerodynamics model before I move on to trying to work out the complex one.

- - - Updated - - -

Oh cool, thanks. How is atmospheric pressure calculated though? Isn't it normally Density*g*height?

Although I guess that's for fluid of a constant density.

Edited by Collider1
Link to comment
Share on other sites

Nope, KSP works it backwards. Atmospheric pressure is this:

CJWeCvX.png

Which is basically the pressure ASL times the exponantial of minus the current altitude over the scale height of the body. It's a very simple (and inaccurate) model, but yeah.

Edited by stupid_chris
Link to comment
Share on other sites

Also, be aware that if you have the PresMat Barometer attached to your ship, kOS can get the readout from it, with SHIP:SENSORS:PRES. I used that in a launch script to work out stock KSP terminal velocity, like so:


// The density of air in kilograms per cubic meter
// at a pressure of 1 atmosphere:
set atmToDens to 1.2230948554874 .

// 'e', as in the natural log base:
set e to constant():e.

// The typical drag coefficient in SQUAD's formula for most parts except parachutes:
// If you assume your ship is made of typical parts and you aren't trying to launch with
// parachutes active, this will also be the average across your whole ship then:
set drag to 0.2.

// m/s^2 gravitational acceleration here (i.e. 9.802 for earth at sea level).
lock heregrav to BODY:MU / ( (SHIP:BODY:RADIUS+SHIP:ALTITUDE)^2 ).

// You can lock this to surface vel, or oribital vel.
// Depending on how high up you are you might want to switch it:
lock useVel to ship:velocity:surface.

print "Current Pressure is" + SHIP:SENSORS:PRES.

// air density here:
lock dense to ship:sensors:pres * atmToDens.

// Force of drag from air pressure here:
lock fdrag to 0.5*( dense )*(usevel:mag)^2*drag*0.008*SHIP:MASS.

// Terminal velocity here:
set termv to ( (250*heregrav)/( dense * drag ) ) ^ 0.5 . // divZero?

Obviously none of this will be right anymore once stock aero gets changed in 1.0.

Edited by Steven Mading
PLEASE SQUAD let me set in my profile that I NEVER WANT auto-smilieys turned on. I hates them.
Link to comment
Share on other sites

Oh that's neat. I will need to be calculating the drag ahead of my ship as well as the current drag, but this will be very useful as a reference for any bug fixing. Thank you. Also, thanks for reminding me that most parts have a drag of 0.2. I was looking in the KOS wiki for a function that would let me sum the drag of the parts.

Link to comment
Share on other sites

Oh that's neat. I will need to be calculating the drag ahead of my ship as well as the current drag, but this will be very useful as a reference for any bug fixing. Thank you. Also, thanks for reminding me that most parts have a drag of 0.2. I was looking in the KOS wiki for a function that would let me sum the drag of the parts.

It's basically a weighted average, basically you want to sum the mass of each part times it's drag coefficient divided by the total mass.

Link to comment
Share on other sites

When I was working out my spreadsheet (which agrees with the formulae posted above, yay) the main surprise was finding that SRBs have a higher drag coefficient of 0.3. I couldn't work out why an RT-10 plus pod wouldn't go as high as I predicted until I spotted that. It was especially annoying as the whole point was to work out how to beat the altitude records one by one in a career game.

Also, bear in mind that if you have massive (as in not massless) parts with a drag coefficient that isn't 0.2, the average coefficient of the craft may change as you burn fuel e.g. a mk1 command pod, parachute plus an RT-10 goes from about 0.28 when full to roughly 0.24 when empty. Another reason to be happy the model will change in v1.0!

Link to comment
Share on other sites

What do you mean? An African or European swallow?

...

What? You must have seen that one coming! :P

I thought drag was calculated in Antioch, swallows are more weight limited ;)

EDIT: To not go completely off topic. I thought FAR used D = .5 * density * v^2 * Cd * A? That's the somewhat standard drag formula I had to learn a LONG time ago.

Edited by Snarfster
Link to comment
Share on other sites

I need to account for air resistance.

Oh and I guess there's drag coefficients on the parts. Where do they come in? Do they represent the area?

Have a look at chapter 5.1 of my Physics of KSP.

One thing to keep in mind is that the air resistence is calculated based on the velocity relative to the atmosphere and not the orbital velocity.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...