Jump to content

Math- Calculating aerocapture height in KSP


Recommended Posts

I found this wonderful resource a few days ago: http://alterbaron.github.io/ksp_aerocalc/ and its source code at https://github.com/alterbaron/ksp_aerocalc/blob/c1b918b6cec2af703b9e1fd66b18d9241619daa2/js/aerocalc.js

I'd really like to understand the math happening here. I'm not familiar with javascript, so the syntax and abbreviated variable names are making that source code really hard to parse, and wikipedia does not provide any equations I've managed to find on the subject.

Would any of you be so kind as to show me exactly what math I'd need to do to calculate exactly what altitude I should set my periapsis to to get a desired apoapsis?

Edited by Amagi82
Link to comment
Share on other sites

I can't give you a formula to plug number into, or anything that you can do by hand. I also don't know javascript, but I know enough other languages that the code is pretty clear.

I'll give you a rough overview of how the code works, for educational purposes. If you have any more questions, feel free to ask.

1) For some trial orbit, (described by current velocity, current radius, and periapsis) which intercepts an atmosphere, the code

a) finds where the spacecraft enters the atmosphere (simple geometry)

B) integrates the equations of motion to determine the spacecraft trajectory in the atmosphere (like KSP's physics simulation, rather than being on rails in time-warp) until

c) the spacecraft (crashes or) exits the atmosphere, and

d) calculates the apoapsis given the atmospheric exit parameters.

Integration of the equations of motion is done by the Velocity-Verlet integration method.

The equations of motion are F = ma = Fgravity + Fdrag. You can find KSP's drag model in the wiki.

KSP atmospheres move with the surface of the planet, so alterbaron's drag model allows you to add or subtract off the velocity of the atmosphere from the velocity of the spacecraft for retrograde or prograde orbits, respectively, when calculating the drag force.

2) Step 1 produces an apoapsis after exiting the atmosphere. It is probably not the apoapsis you want. Since you can't just solve analytically for the periapsis which produces your desired apoapsis, this code uses a root finding method: specifically, the method of bisection. So the code follows the spacecraft through the atmosphere a bunch of times, each time narrowing in a bit more on the trajectory which gives the desired apoapsis, if it exists.

3) If successful, the code spits out not a periapsis, but a maneuver. There are many possible maneuvers which would give you the same periapsis, depending on how much you burn prograde/retrograde versus how much you burn radially. But the different maneuvers would give you different post-aerobraking apoapses. Likewise there are many maneuvers which give different periapses, but the same post-aerobraking apoapsis.

alterbaron's step 2 only tests maneuvers which change the direction of your vehicle without changing your current speed. It is a nice way to reduce a two-dimensional problem (burn direction + burn delta-v) into a one-dimensional problem (burn direction, with delta-v determined by keeping speed fixed). This vastly simplifies the procedure in step 2 to find the desired maneuver. You would have to use a two-d minimization method, instead of a root-finding method. It may not always give the minimum delta-v maneuver, but it probably does a pretty good job most of the time.

Edited by Yasmy
Now with 50% more politeness!
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...