Jump to content

how does ksp calculate acceleration exactly?


surge

Recommended Posts

Hello,

It's well known that F=m*a, and perhaps lesser well known that F = G*M1*M2/R^2.

Which one does ksp use to determine velocity/acceleration? i.e. does it account for the ship's mass. And no, I'm not asking about rocket thrust, for which I know it (roughly) does account for, I'm simply talking about a free-falling object. Ideally on a body with no atmospheric drag.

I have already painstakenly determined that for moons orbiting other planets, it does not use the second mass to implement the orbital characteristics. Those are all 'on-rails' or fixed/nerfed to defy the exact laws of physics though (in order to implement the scaling). I've heard ksp is a 2-body system, but in that case it's really 1-body. I'm guessing they meant it's 2-body when calculating the physics for ships?

I could test this using kOS and writing a bunch of code to measure it, but for the moment, it seems easier and quicker to ask here.

Edited by surge
Link to comment
Share on other sites

5 hours ago, sevenperforce said:

Doesn't account for satellite mass.

I guess you meant Does.

But yeah, I've since done some calculations and measurements that indicate when dealing with ships, it Newton's gravitational law, not 1st law. Thanks.

I think I also got a bit befuddled because I'm trying to do crap like integrals, and the only ones that are useful are apparently something called 'definite integrals' whereas every maths teacher starts with the other kind and that makes me angry because I can't check and test them with a computer.

In other words, I'm trying to calculate the distance above the body I should start thrusting in order to hit it at near, or exactly 0m/s! That's a definite integral of some kind as gravity changes, but I'm a bit stumped for now.

So far I have a throttle setting of mass*mu/R^2, to neutralize acceleration entirely, but if we're going at 800m/s, and trying to land, that can only end in disaster!

Edited by surge
Link to comment
Share on other sites

8 hours ago, surge said:

Hello,

It's well known that F=m*a, and perhaps lesser well known that F = G*M1*M2/R^2.

Which one does ksp use to determine velocity/acceleration? i.e. does it account for the ship's mass. And no, I'm not asking about rocket thrust, for which I know it (roughly) does account for, I'm simply talking about a free-falling object. Ideally on a body with no atmospheric drag.

I have already painstakenly determined that for moons orbiting other planets, it does not use the second mass to implement the orbital characteristics. Those are all 'on-rails' or fixed/nerfed to defy the exact laws of physics though (in order to implement the scaling). I've heard ksp is a 2-body system, but in that case it's really 1-body. I'm guessing they meant it's 2-body when calculating the physics for ships?

I could test this using kOS and writing a bunch of code to measure it, but for the moment, it seems easier and quicker to ask here.

Ok so lets break this down here.

KSP doesn't  really use either of these. Being a computer it solves things numerically, so (and this is a pretty huge simplification, possible not 100% accurate to the way it's implemented in KSP) at each time-step (roughly once per frame, but not necessarily) it calculates the force on he ship due to the gravitational body that the ship is in the SOI of. It then changes the velocity of the ship based on this force, and the acceleration is just the difference between the new speed and the old speed divided by the time between the time-steps.

If you want to find the acceleration due to gravity at any given point, assuming that it is falling directly straight down with no other forces acting on it, then you can use your second equation to work out the force due to gravity and then the first equation to work out how much that is going to accelerate it.

 

Hope this helps, please ask if I'm not clear on anything. :)

Link to comment
Share on other sites

Right, but since F = GMm/R^2 changes (because of the R) as you descend, how  do you figure out at what altitude to thrust at to get to 0 velocity at a particular value of R. i.e. land without crashing at a bajillion km/hr?

I've figured out it's the integral (area in non-stupid terms) of F=GMm/R^2, combined with something like d =v1t +1/2 at^2?. I'm pretty lost at this point, but all I want is given a thrust value, a distance to stop within. The forces are a necessary nastiness of doing this properly, right?

I've come up with MU/R^2*mass which will give you the thrust to cancel out acceleration from gravity, i.e you will decend (or even ascend) at a constant speed. I'm lost as to how to proceed.

For reference: https://www.mathsisfun.com/calculus/integration-definite.html

I'm still reading through and trying to understand...

And disappointed not one of you has regurgitated an equation for me to use.

Link to comment
Share on other sites

2 hours ago, surge said:

Right, but since F = GMm/R^2 changes (because of the R) as you descend, how  do you figure out at what altitude to thrust at to get to 0 velocity at a particular value of R. i.e. land without crashing at a bajillion km/hr?

I've figured out it's the integral (area in non-stupid terms) of F=GMm/R^2, combined with something like d =v1t +1/2 at^2?. I'm pretty lost at this point, but all I want is given a thrust value, a distance to stop within. The forces are a necessary nastiness of doing this properly, right?

I've come up with MU/R^2*mass which will give you the thrust to cancel out acceleration from gravity, i.e you will decend (or even ascend) at a constant speed. I'm lost as to how to proceed.

For reference: https://www.mathsisfun.com/calculus/integration-definite.html

I'm still reading through and trying to understand...

And disappointed not one of you has regurgitated an equation for me to use.

This is where it get complicated. 

Unfortunately you can't use d =v1t +1/2 at2 because it assumes constant acceleration which, as you noticed, you do not have.

None of us have regurgitated an equation because there isn't a simple one. To get your answer you have to solve a differential equation, not an integral. I can post an equation up later (I should be studying right now), so in the mean time you might want to read up on differential equations.

 

EDIT:

Ok, having now woken/caffeined up and had a look at this properly, I don't think this is a problem you can solve analytically (i.e with an equation). Unless I'm wrong (which is entirely possible) you end up with a set of coupled differential equations where change in velocity is related to the height, but change in height is related to velocity (i.e a non-linear system). Thus the only way to get an answer is to do it numerically.

EDIT 2:

Yeah so if you want to solve this, you'll have to assume that the acceleration due to gravity is constant all the way down (which is mostly valid close to the surface, like on Earth you would just assume 9.81 ms-2 the whole time). In that case it's pretty doable; there are plenty of examples of "Suicide Burn" (that's the name of the manoeuvre you're trying to calculate) calculators for KSP around if you Google.

Edited by Steel
Link to comment
Share on other sites

Acceleration is the change in velocity.

Force is a cause for acceleration.

 

So : Your acceleration depends on what force are actually working on you (or in your case).

It... might come with differential equations...

Link to comment
Share on other sites

Steel, thanks for your input.

But this whole "its not possible" garbage I've heard before and proven wrong (I cant remember the url, but search my name, perhaps)

I've nailed it down to what's called the definite integral according to that website.

The area of the graph of say, speed vs altitude when the 'german s' equation is newtons gravitational law. I wonder which integral rule I should be using to calculate the distance required for the final speed to equal 0?

Link to comment
Share on other sites

3 hours ago, surge said:

Steel, thanks for your input.

But this whole "its not possible" garbage I've heard before and proven wrong (I cant remember the url, but search my name, perhaps)

I appreciate your enthusiasm, but when you try to solve this taking into account changes in gravitational force you get a non-linear system of equations, which are notoriously difficult to work on and you have to be very lucky to get one with a trivial solution.

The website you mention where it all boils down to an integral is either assuming constant gravitational acceleration or its an integral with no analytical solution.

 

Link to comment
Share on other sites

Better Different solution: Energy.

E=mgx + 1/2mv^2  Gravitational potential plus kinetic energy. Presumably you're moving towards the ground at a significant speed. If you take x=0 to be on the surface, it's clear that you want E=0 on the surface too (otherwise splat). For simplification reasons, we'll take mass as constant.

g=GM/(x + R)^2  Universal gravitation. x=0 on the surface, so we need to add the radius of the body.

v=\int(a)dt  Velocity is the integral of acceleration with respect to time. Your velocity changes by an amount dependant upon your acceleration every second.

a=g - F/m  Acceleration is the difference between gravity and thrust/m.

So that gives us:

E=GMmx/(x + R)^2 + 1/2m\int(GM/(x + R)^2 - F/m)dt

G, M, m, R, and F are constants, which leaves us with x and t.

P=Fv  Engine power output is thrust times velocity (Nm/s = W).

P=F * \int(GM/(x + R)^2 - F/m)dt Substitution

I leave the rest as an exercise to the reader, as I've managed to confuse myself. I'm not even sure if I'm trying to get things to be in terms of time or altitude. :confused:

Edited by 0111narwhalz
Link to comment
Share on other sites

4 minutes ago, 0111narwhalz said:

Better Different solution: Energy.

I did think about energy. However, energy doesn't tend to simplify thing to do with time, as then you need to know the change in kinetic and potential energy per unit time, which is essentially the same as knowing the change in height and velocity per unit time, so you end up with the same problem.

Link to comment
Share on other sites

16 hours ago, surge said:

Hello,

It's well known that F(total)=m*a, and perhaps lesser well known that F(gravity) = G*M1*M2/R^2.

Just so that's clear.

Also, there's a little re-arrangement that can be done if gravity is the only force acting on your vessel.

m1*a(tot) = F(tot) = F(grav) = G*m1*m2/r^2

m1*a(tot) = G*m1*m2/r^2

Divide out m1:

a(tot) = G*m2/r^2

Therefore, under Keplerian 2-body mechanics, the acceleration of a satellite is dependent only on G and the mass of the body it is orbiting*, and the distance. The "on-rails" approximation is that your satellite does not affect a planet's or moon's trajectory, an approximation that is quite valid when Gilly is still 100 billion times more massive than even a 1000-ton uber-lifter.

*This is usually combined into the standard gravitational parameter, mu.

10 hours ago, surge said:

In other words, I'm trying to calculate the distance above the body I should start thrusting in order to hit it at near, or exactly 0m/s! That's a definite integral of some kind as gravity changes, but I'm a bit stumped for now.

That's not going to be easy to do, and I'm pretty sure this becomes some sort of nasty differential equation for which no trivial analytical solution exists, requiring numerical solution: effectively a simulation (such as KSP).

And if you're wondering: yes, this is basically math-speak for "abandon all hope, ye who enter here".

1 hour ago, 0111narwhalz said:

Better Different solution: Energy.

Pretty sure you still get the differential equations, since you incur gravitational losses, etc.

Link to comment
Share on other sites

1 hour ago, 0111narwhalz said:

Better Different solution: Energy.

Energy-conservation based methods are not deterministic. Lagrangian and Hamiltonian are both methods that relies on exactly that, and indeed you can tell whether an end state would be reached - but nothing says what happens in between, which is what OP wanted as well I think.

I suppose you can make up the differential equations, but I'm not yet in position to really think them.

Link to comment
Share on other sites

The kind of problem exposed has got my interest since quite some time. Don't want to annoy the whole audience, many have already shown important equations (in particular, about gravity acceleration) so won't repeat all that stuff. However, let me show a couple very important equations valid for any elliptical or hyperbolic orbit, including suborbital trajectories, that I haven't seen reported yet:

- r = a (1-e2) / (1+ e cos(θ))

- v2 = Gk Mb (2/r - 1/a)

with r = distance of object from focus (mainbody center); a = SMA; e = eccentricity; θ = true anomaly; v = velocity; Gk = gravitational constant; Mb = mass of mainbody.

Those two equations are all that is required to derive exactly the speed at any point, including at the specific distance r = (body radius + altitude of ground ASL) where the vessel would impact the surface.

Unfortunately, those aren't enough to provide an analytical general equation for the problem of arriving at 0 speed. Energy equations provide an elegant solution but still can't handle changes in vessel mass during a deceleration burn. Don't want to show what came when I tried to integrate just one of the variables (pitch angle φ) in time trying to find an analytical equation for this problem.

In the end, I am using a numerical solution (currently have it on a spreadsheet) that effectively solves the problem perfectly. Which is actually alike what I could find used by all space agencies in reality.

Link to comment
Share on other sites

I believe there's some overthinking going on here.

Kerbin's radius is rather small compared to real bodies, so this matters more in KSP than in real life, but you can easily calculate (by r^2 comparison) the difference in gravitational acceleration between, say, the surface and orbital height.  Generally, unless your velocity is so high and/or your thrust so low that you'll have a burn longer than a minute or so, your r won't change enough to worry about, and you'll be safe to assume the g for the surface to calculate your suicide burn.  This will actually cause you to kill your velocity a little high, which is better than doing it a little low (lithobraking tends to be hard on equipment).

Link to comment
Share on other sites

KSP: probably just scales the "g" force of the SOI you are in to the radius(squared) you are from the center of the SOI.  Other SOI (typically Kerbin, plus the main planet if you are in a moon's SOI) are almost certainly included a constant over the entire SOI (but they are obviously there, otherwise you would be flung out of the SOI during approach).

Principia: Presumably using F=Gm1m2/r**2.  Don't expect the "on rails" time acceleration to work (KSP's works because it cheats) "on rails".  Don't expect the plotted trajectory to be all that accurate (although it should be good enough unless you loaded Principia to do the things KSP's gravity can't).  I haven't played with Principia, and am amazed that KSP's cheat works as well as it does (down to the "slingshot maneuver").

Link to comment
Share on other sites

1 hour ago, wumpus said:

KSP: probably just scales the "g" force of the SOI you are in to the radius(squared) you are from the center of the SOI.  Other SOI (typically Kerbin, plus the main planet if you are in a moon's SOI) are almost certainly included a constant over the entire SOI (but they are obviously there, otherwise you would be flung out of the SOI during approach).

I'm pretty sure that's incorrect.

KSP uses the 2-body Keplerian approximation. This means:

Your vessel is acted on by only one body's gravity at any given time. This means no Lagrange points, ITN, etc, but is a reasonable approximation for most conditions.

As a side effect, this means that explicit spheres of influence must be defined, where there is a sharp boundary between the gravity of two major bodies. When you go from Kerbin's SOI to Mun's SOI, you instantly stop being affected by Kerbin and become affected only by the Mun.

During physics, orbits are essentially a byproduct of your current velocity and position relative to the body whose SOI you are in. Your vessel is propagated using Newton's laws of motion. Were you to run this with perfect accuracy and infinitely short timesteps, this would perfectly reproduce the on-rails orbits. However, the integration schemes used for off-rails physics are designed to deal with accelerations not caused by gravity, and quickly become inaccurate over time once you start to factor in finite timesteps and machine precision.

With on-rails orbits, KSP essentially takes your position and velocity, and calculates the six primary orbital elements: SMA, eccentricity, inclination, longitude of the ascending node, argument of periapsis, and mean anomaly at epoch. Given the simplicity of the 2-body Keplerian approximation, it is trivial to predict where your position will be at any arbitrary point in the future or past, so that is what KSP does*. The only semi-complication is when you have either SOI changes or sudden, unexpected lithobraking events, and KSP's patched-conics integrator does a reasonable job of patching those conics.

*Under the 2-body Keplerian approximation, except during SOI changes, the shape of your orbit (SMA + eccentricity), period of your orbit (SMA), and orientation of that orbit relative to the parent body (inclination, LAN, AP) cannot possibly change unless you have some non-gravitational force (such as an engine) acting on your vessel. The only two things that need to be specified from there are: what time it is right now, and how far along in the orbit you were at some arbitrary point of time in the past.

1 hour ago, wumpus said:

Principia: Presumably using F=Gm1m2/r**2.  Don't expect the "on rails" time acceleration to work (KSP's works because it cheats) "on rails".  Don't expect the plotted trajectory to be all that accurate (although it should be good enough unless you loaded Principia to do the things KSP's gravity can't).  I haven't played with Principia, and am amazed that KSP's cheat works as well as it does (down to the "slingshot maneuver").

I'm pretty sure @eggrobin has made sure the projected orbits in Principia are reasonably accurate out to a fairly long time in the future. Unlike the Keplerian approximation, the shape and orientation of your orbit can change, and so there's no simple, analytic equation to tell you where an object will be after X time; he had to effectively use some advanced mathematical techniques similar to (if not outright identical to) what NASA and other space agencies use to estimate their orbits.

Fast-forward a billion years in stock KSP, your satellite will be exactly where you left it (assuming it doesn't cross the SOI of any other major body). Fast-forward a billion years in Principia, you can't even be sure it's still orbiting the same object.

EDIT: Also, to clarify why 2-body is a reasonable approximation: imagine Kerbin, the Sun, and a satellite. While the Sun has a not-insubstantial effect on the satellite's orbit, it has an almost identical effect on Kerbin's orbit. As such, if you're looking at position/veocity/acceleration of your satellite relative to Kerbin, you can simply ignore the Sun's gravity, because Kerbin is being accelerated at (almost) the same rate too.

EDIT 2: As a demonstration of that: it's entirely possible to have a satellite orbiting Gilly that is feeling more gravity from Eve than Gilly. Assume Gilly is at periapsis, and you have a satellite 10 km from the edge of Gilly's SOI, towards Eve. It's getting 0.0376 m/sec^2 of acceleration from Eve, and just 0.00050 m/sec^2 of acceleration from Gilly. The reason why Gilly is the "major body" is that Gilly itself is being accelerated at 0.0369 m/sec^2 by Eve. Subtract it out, and the "missed" acceleration is just 0.00065 m/sec^2 under 2-body Keplerian mechanics, and this is a rather worst-case scenario.

Edited by Starman4308
Link to comment
Share on other sites

MechJeb has an autopilot for it already. KER can show you the distance to the special point I suppose...

Spoiler

Alright. Some things to have :

Basic differential equation that describes normal orbit (ie. no external force) :

F = m((d(r^2))/((d^2)t)) = -(GMmr)/((||r||)^3) (grav. force pulls inwards)

or,

0 = m((d(r^2))/((d^2)t)) + (GMmr)/((||r||)^3)

If an external force is to be applied (assuming no mass changes and constant direction away from center) :

Fext = m((d(r^2))/((d^2)t)) + (GMmr)/((||r||)^3)

notes :

r is vector

F is vector

Fext is vector as well.

Probably some solve would require some vectorial things in it, which, let's be honest, I haven't learned either XD

The limits would be :

At t = 0 (for simplification), r = planet's radius + height at site

t = 0, dr/dt equals zero

t = 0, d(r^2)/(d^2)t = (Fext/m - surface g)

Suicide burn starts at a negative t.

 

Edited by YNM
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...