Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Planets gravity and orbiting

Discussion in 'General' started by jhnwgacy, Aug 29, 2015.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. jhnwgacy Trainee Engineer

    Hello, engineers!

    Here is some nerdish stuff about gravity in upcoming planets update. And about orbiting planets.

    When i've got a compiled sourcecode of SE with planets enabled, my first interest was: if it's possible to send a ship to stable orbit and make it a satellite? So i've tried to do things like if it was KSP: start from surface, gain some height and then prograde towards horizon till i get enough speed to maintain stable orbit. And then turn off dumpeners and look what i got.

    With standard settings, however, i failed 3-4 times to maintain orbit. The speed is too height and i fly away from gravity range or it's too low and it ends up with crushing into planet.

    So i became curious how gravity is calculated and affects ships in this alpha vers. I've built this small ship with detachable probe:
    SpaceEngineers 2015-08-29 19-33-08-34.jpg
    The probe has a program block and a text panel.
    SpaceEngineers 2015-08-29 19-33-19-96.jpg
    It falls free from space to planet surface and each 15 ticks logs coordinates to text panel.

    After drone crashes to surface, it's possible to recover data from text panel and paste in excel to calculate speed and acceleration for each quarter second of fall.
    SpaceEngineers 2015-08-29 19-42-19-71.jpg
    SpaceEngineers 2015-08-29 19-41-16-11.jpg
    SpaceEngineers 2015-08-29 19-43-08-61.jpg
    Also, if we drop our probe from 2 different points, we can calculate center of planet coords by finding intersection of two vectors. Having coords of center of planet mass, its easy to find R (height from planet center) for each acceleration measurement.
    So, i dropped my probe 2 times, recover data, pasted it to excel and look what i've got:
    At first look you can guess that it's all right with acceleration here, but in each point acceleration of gravity should be equal to GM/(r*r), so we can find GM parameter for this planet: GM=a*r*r
    Let's look at this:
    GM is changing with height. And it's changing much (6x for surface in comparison with ~ 10 km above). So this is the reason why my ship doesn't become a satellite.

    Attached Files:

    Last edited: Sep 1, 2015
    • Like Like x 9
  2. jhnwgacy Trainee Engineer

    But it's hard to be satisfied with such disappointing results, so i started to brouse sourcecode to find how they calculate gravity. I found GravityFalloff parameter, whic was not defined in sourcecode and is loaded from world data. I found it in my save file finally. It was set to 7.
    So if 7 is too steep falloff, then what will happen if i set it to 1? Will it mean natural gravity?
    Lets see.
    Worls was loading a bit longer, but nothing critical, i've got a panet with higher gravity range and more smooth gravity falloff.

    So let's drop our probe again and look what it will bring us this time.
    (Actually, i've tried to launch ship to orbit first and it started circling arond planet like if i was playing KSP, so i was really inspired and sutisfied with results, even thought that gravity is reallistic now, but back to our probe).
    GM is not a constant again, it has not so wide range now (1.5x instead of 6x) and doesn't spoil satellite orbit too much, but it's not correct.
    So i guessed, what if in this world gravity is proportional to 1/R instead f 1/(R*R).
    And yes, it's really so, gravity fallof is proportional to R.
    But, if g=GM/r, the orbit won't look like in real world. At first i thought, that it will look like a downgoing spiral and satellite will need to use some thrust to raise orbit from time to time.
    So, i've launched the same ship with a probe on orbit (tried to make orbit as close to circle as possible) and logged velocity and height from center of planet each 5 seconds in total time of 75min.
    • Like Like x 6
    • Informative Informative x 1
  3. BlackUmbrellas Senior Engineer

    I know that WastedSpace sorrrrt of made a satellite while using a small player-made planetoid and the natural gravity mod; he tried making a remote-control rocket/missile but forgot to add a gyro, so when he launched it it accelerated out of antennae range and then started falling back to the planet, getting caught up in a highly elliptical orbit. IIRC it was slowly decaying, but, over the course of a few hours it didn't crash.

    Obviously real planets will be much larger, so I guess maybe the same thing isn't possible?

    Shame. It'd be nice to have camera satellites.
  4. jhnwgacy Trainee Engineer

    So, look what we got:
    Satellite made 9 circles around planet, has not lost height and velocity, despite my guesses, that it will loose height with each circle.
    But in 9 cicles around planet this probe made 12 apoapsis and periapsis points. And look how strange height of orbit changes.

    That's what you get when you brake the physics:).
    But, anyway, it's good that orbiting is available. I really wait for planets to be released.
    • Like Like x 6
  5. fourthquantum Senior Engineer

    Have you tried varying the mass of the probe? It shouldn't matter in the real world but in the game that may not be the case.
  6. jhnwgacy Trainee Engineer

    I've tried to drop virious things, they are falling with the same acceleration. So it's OK with mass.
    The strange thing is the gravity falloff proportional to Radius directly, not to square of radius.
    I guess it will lead to strange picture when elliptical orbit will turn a bit each orbit period and instead of orbits going the same way every turn , you ll get a number of elliptical orbits in a shape like flowers petals.
  7. BlackUmbrellas Senior Engineer

    Sorry, the math and charts here go a bit over my head; without messing with the constants for the gravity, is it possible to put something in orbit right now?
  8. The Q Apprentice Engineer

    Actually all Spacecraft/stations build by humans need to do correction burns to stay in orbit (due to oxygen atoms slowly slowing them down) i think its weekly or maybe more often
  9. jhnwgacy Trainee Engineer

    Yeah, thats because atmospere never ends absolutely and space stations having arrays of solar panels are loosing speed even in very rarefied atmosphere.
  10. jhnwgacy Trainee Engineer

    But here you don't lose speed or height.
    I think, what if i log a more stretched orbit? Will it draw me flower petals?:)
    Should try this.
    Last edited: Aug 29, 2015
  11. BlackUmbrellas Senior Engineer

    I don't think that that's strictly speaking true.

    The ISS is in Low Earth Orbit; it's technically still inside the upper atmosphere. But satellites in higher orbits are outside the atmosphere and don't suffer drag. Any course corrections would be because of inaccuracies in the orbit, not because they're being slowed down by air drag.
  12. jhnwgacy Trainee Engineer

    Yes, it's possible.
    I needed only to change gravity falloff in save file. Look for path like:
    C:\Users\max\AppData\Roaming\SpaceEngineers\Saves\76561198124730542\"Your save"\SANDBOX_0_0_0_.sbs
  13. BlackUmbrellas Senior Engineer

    So, possible, but you need to mess with the gravity constants to do so. That answers my question, then.
  14. fourthquantum Senior Engineer

    Could you change the axis to 1/r^2
  15. Draygo Senior Engineer

    So what specific falloff setting did you use?
  16. Knsgf Junior Engineer

    Gravity fall-off power is defined in Sources\SpaceEngineers\Content\Data\PlanetGeneratorDefinitions.sbc. To get Newtonian natural gravity, set it to 2.
    • Like Like x 1
  17. jhnwgacy Trainee Engineer

    Thanx, I'll try it!
  18. SirLANsalot Apprentice Engineer

    to get a perfect geo synchronous orbit (aka hovering) you WILL need to use a small "grav drive" to counteract the planets pull. I would of assumed that if you had enough thrusters, that dampeners would be enough to keep you in one spot. Sadly that is not the case, even with modded high output thruseters your ship WILL slowly fall to the surface.

    Would like to find a more updated compile of planets rather then the one I have from v1.091. Seen some people here on the forums posting pics of a newer dev build.
  19. jhnwgacy Trainee Engineer

    Yes, I have 1.091 too, got errors when tried to compile new source.
  20. Nacon Junior Engineer

    So much Science in this thread. Loving it! :D
  21. jhnwgacy Trainee Engineer

    And i confirm, that Setting GravityFalloff = 2 gives you realistic Newton gravity.
    I've droped my probe last time and got pretty good measurements:

    By the way, If G is really equal to 6,67408(31)·10−11, the total weight of my planet is 4,51685E+19 kg.
    And with radius of 24660m, it's average density is 719064,5 kg/m3.
    Pretty heavy stuff, not a black hole, not even a neutron star but still 720 times heavier than water :-.)
    Last edited: Aug 30, 2015
  22. fourthquantum Senior Engineer

    Do you have the raw data?
  23. jhnwgacy Trainee Engineer

    and those pikes near 29000m (4.5km above surface), i know they probably caused by engine starting drawing more detailed surfaces, but want to belive, that this is because of shaking while entering atmosphere :)
  24. Knsgf Junior Engineer

    In 1.094 source ships with inertia dampeners on hover in place instead of sinking down.
  25. jhnwgacy Trainee Engineer

  26. fourthquantum Senior Engineer

    Could you plot acceleration vs 1/(r^2) and see if it's a straight line? I'm trying, but I'm stuck with a tablet at the moment and it's proving harder than I expected to do it.
  27. jhnwgacy Trainee Engineer


    Not a perfect straight line, i'd say..
    Near surface i got relatively less results, cause probe falls with speed over 200m/s.
    This also can cause measurements errors, game engine is not perfect with speeds over 104m/s limit.
    Maybe if i drop it multiple times from different heights, i'll get more accurate results.

    But, orbiting works perfect with gravity falloff set to 2. Gravity range is restricted tho, what makes you to keep all points of your orbit inside this range to stay bound to planet.

    Here some playing with orbiting:

    • Like Like x 2
  28. Knsgf Junior Engineer

    The gravity "border" is defined by the following code in Sources\Sandbox.Game\Game\Entities\MyPlanet.cs, line 494:
            public bool IsPositionInRange(Vector3D worldPoint)
                return (WorldMatrix.Translation - worldPoint).Length() < 2.0f * m_planetInitValues.AveragePlanetRadius;
    To increase gravity extent change 2.0f constant to a bigger value.
  29. jhnwgacy Trainee Engineer

    I've experimented a bit more with gravity and orbits.
    Gravity falloff set to 2, which should mean realistic Newtonian gravity.
    But, it seems, that it's not perfectly Newtonian however, and this curve is not just a measurement error.
    Periapsis and apoapsis points of orbit are still shifting a bit with every turn.
    Orbit period=637 sec and apoapsis period is 647 sec.

    They shift now just a little bit, but surely i'm getting orbits like on this pics:

    perihelion-precession.gif precessing_kepler_orbit.gif

    I guess, Gravity falloff is a coefficient, it's not a "selector value", cause it takes float values.
    Probably, perfect value lies somewhere between 2 and 1,9.
    I'm going to find it.
    (he he, later i looked into source and understood how naive was this proposal:))


    Plotted coordinates on 3d chart, so that's how it looks:
    Last edited: Sep 4, 2015
    • Like Like x 2
  30. fourthquantum Senior Engineer

    I wonder if it's possible to write a program for the programable block which stabilises an orbit by taking these positional results into account?
Thread Status:
This last post in this thread was made more than 31 days old.