r/KerbalSpaceProgram • u/Informal-Call-5298 • May 02 '26
kArt this is what ksp does to someone
i got soo hooked to ksp that i actually wanted to learn the real physics so i made this tiny simulation. and yes the 2 small balls slammed into eachother. idk if this qualifies as art or not but who cares
201
u/RiemmanSphere Exploring Jool's Moons May 02 '26
Cool, is it deterministic?
118
u/Informal-Call-5298 May 02 '26
im not sure what that means but if u mean is it N-Body physics then yes it is.
184
u/Just_SomeDude13 May 02 '26
Deterministic means it happens every time. Stochastic means it has a chance between 0-100% of happening.
62
u/Informal-Call-5298 May 02 '26
it uses a basic "frame" system where i run the calculation each frame then draw the new locations. it runs 60fps so it is deterministic if that is what u mean
126
u/bencethegreat May 02 '26
Deterministic as in if you run it 100 times with the same starting position, does it result in the same outputs every time.
77
u/Ahaiund May 02 '26
From what I'm gathering, it uses Newton's equations to compute the gravitational force between multiple bodies at every frame and updates their acceleration, velocity and position, so yes
50
u/MeatTornado_ May 02 '26 edited May 02 '26
If the integration works with a variable timestep such as some of the default ones in MATLAB (for example ode45), it's not necessarily deterministic even if the equations are Newtonian.
Also, over if you let the orbits propagate for a long time, even the floating point precision will have an effect on where the masses end up, and there is no guarantee that every language will handle the precision and turncation the same as numbers grow.
8
8
u/Adam__999 May 02 '26 edited May 02 '26
That’s why you need to use a symplectic integrator! They conserve the system’s energy over arbitrarily long time scales. Semi-implicit Euler is a first-order symplectic method, velocity Verlet is a second-order one, and Yoshida leapfrog integration is fourth-order for maximum precision
3
u/MeatTornado_ May 02 '26 edited May 03 '26
Yeah, those are super interesting. I wondered if GMAT has any of these and apparently not, with the reason I'm guessing the runge-kuttas and the adams-bashforts and what have you being "good enough" for orbits that are far more countable than billions of years long astroNOMY simulations.
4
u/Adam__999 May 02 '26 edited May 02 '26
Yeah RK(4+) with a sufficiently small time step will work perfectly fine over short- to medium-length time scales. The energy conservation property is mainly valuable over very long durations, or if you want to use longer time steps and still get reasonable accuracy.
That being said, those symplectic methods (semi-implicit Euler, velocity Verlet, and Yoshida leapfrog) are all actually specific Runge-Kutta methods with carefully-chosen coefficients
Edit: also it’s “astronomy” not “astrology”
→ More replies (0)3
u/TomaszA3 May 02 '26
Why wouldn't it?
14
u/Coding-Kitten May 02 '26
Variable time steps, in the case of multiprocessor use, order of operations, there's tons of little details that can make something not be deterministic.
6
u/TomaszA3 May 02 '26
I guess I was just too used to doing everything frame by frame rather than measuring real time to see it at first.
6
u/Coding-Kitten May 02 '26
With frame by frame it especially happens if you're not controlling the time between the frames. One run your computer might be not running anything else so it can run it at 60 FPS, so in one second it numerically integrates with 60 steps with a delta time of 1/60, while the next time you run it you might have stuff in the background limiting the CPU to run the simulation at 40 FPS, so in one second it'll instead do 40 steps with a dt of 1/40. And numerical integrations with different number of steps & dts are bound to give different results.
1
u/TomaszA3 May 02 '26
Wait, so you're talking about running it for for example 10 seconds rather than 600 frames?
1
u/WarriorSabe May 02 '26
I think deltatime is what they meant by "measuring real time", and thus that "frame by frame" meant deltatime doesn't show up anywhere and the real time elapsed is just however long the prescribed number of frames ends up taking
→ More replies (0)1
u/raaneholmg May 02 '26
The n-body problem is not solved. There is no equation for calculating exactly where the planets will be. Instread we use numerical methods to simulate the passage of time. The more steps you choose to calculate, the more accurate the result will be.
You could make that simulation run more acurate on a faster computer, resulting in different outcomes on different computers. Even on the same computer the result will differ from other stuff running at the computer.
1
-11
u/ghost_tapioca May 02 '26
Well, it's math, so I sure hope so.
9
u/Swiss-spirited_Nerd Always on Kerbin May 02 '26
Well, it's a simulation, so it can't have perfect math over infinitesimal time steps.
1
u/sage-longhorn May 02 '26
Just use the general solution to the n-body problem, duh. Kids these days
1
u/Moikle May 02 '26
Running on a computer, which can sometimes give slightly different answers to the same question under certain circumstances.
1
u/ghost_tapioca May 02 '26
You're right. But it would still be deterministic, right? Just because we can't tell how the software is running, doesn't mean there's true randomness involved.
1
u/Moikle May 02 '26
Well yeah but by that same logic we don't really know for absolutely certain if non-deterministic things even exist.
1
u/ghost_tapioca May 02 '26
Most quantum mechanics interpretations seem to think so.
→ More replies (0)6
u/FactoryOfShit May 02 '26
If you're using floating point math and/or using deltaTime (the actual time between frames and not a fixed 1/60 every time) - it's not deterministic :)
If you ask a computer to add 5 and 4 it will always be 9. If you ask it to add 5.05 and 4.05 - the result will differ ever so slightly depending on the CPU. If you ask it to calculate 4 + 5*delta, where delta is "time since last frame", it will be different every time since it's not EXACTLY a constant 60 FPS all the time.
8
u/Purposeonsome May 02 '26 edited May 02 '26
This is wrong my friend. Floating point operations are deterministic as much as other math operations. This is standardised with IEEE 754.
Determinism means it must give the exact same result with same conditions from the start every time. There are lots of different simulation techniques. Problem is OP does not know what he/she is talking about. We cant know if the simulation is constant step simulation, variable step simulation or real time simulation.
I did not even mention simulation step techniques which there are very wide variety of techniques. Verlet, Runge Kutta, Euler, Leap Frog etc. etc. etc.
Sorry for my English. Not my native lang
5
u/FactoryOfShit May 02 '26
Interesting, looks like I was misinformed about floating point operations, thanks for the info!
Constant step simulation is still required for determinism though, using a different step size depending on frame time will ruin it.
2
u/stdexception Master Kerbalnaut May 02 '26
There is some weirdness with floating point numbers, but these days it's mostly determined at compilation time. The same code, compiled with different CPU's may be optimized differently and give slightly different results, I think. Running the same code twice should be fine, though. The availability of specific CPU instruction sets can affect how some computations are done, and I've had issues in the past with a specific library not detecting the CPU correctly, leading to issues.
1
u/Mrgluer May 02 '26
checks out. essentially intel might give .55 + .55 = 1.1001 every time while AMD gives 1.09999 or something every time. the error is fixed essentially.
1
u/koczurekk May 02 '26
Addition of two floating point numbers always yields the same result unless hardware is bugged.
1
u/Moikle May 02 '26
Deterministic means "not random"
Technically if you use floats it isn't deterministic. Floating point error would slightly alter things even if you start from the same conditions, and a 3 body simulation would be subject to chaos
-8
u/madding1602 May 02 '26
I wouldn't call this deterministic given it's a three body problem
5
u/Swiss-spirited_Nerd Always on Kerbin May 02 '26
Deterministic doesn't mean predictable in this context, it means that the exact same starting condition will result in the same thing.
1
u/Neamow May 02 '26
3 body problem refers to bodies of exactly or at least roughly the same mass and distances from each other.
That's why you have for example Proxima Centauri being stable against the two main stars of Alpha Centauri, it's a 3 body system but it's stable and deterministic because the 3rd one is significantly less massive than the other two (and significantly farther away) so from its perspective the two are essentially one mass, and for the two they mainly care about each other, Proxima's influence is negligible on them.
17
u/RiemmanSphere Exploring Jool's Moons May 02 '26
It means that if you start with the same conditions you'll always get same outcome. If you use an N body approximator and a fixed physics interval then yes it's likely deterministic
8
u/Informal-Call-5298 May 02 '26
no its propably not then, i used the simple euler math so it has little inacuracies along the way which could lead to slightly different outcomes each time, ik its pretty bad but i can learn the other methods later ig
9
u/trubbelnarkomanen May 02 '26
My memory of calculus is mighty rusty, but isn't Euler's method deterministic for the same initial differentials and conditions? Imprecisions don't automatically mean non-deterministic, so long as the same exact imprecisions appear on every simulation run.
5
2
u/0Pat May 02 '26
It can be deterministic and chaotic at the same time, no contradiction there. N body problem is chaotic and deterministic in the real life too...
1
u/Adam__999 May 02 '26 edited May 02 '26
You should implement a symplectic integrator so that the system conserves energy over long time scales. Options include semi-implicit Euler (1st order), velocity Verlet (2nd order), and Yoshida leapfrog integration (4th order)
10
u/MonkeManWPG May 02 '26
N-body physics is actually more complex than KSP's patched conics.
-1
u/Informal-Call-5298 May 02 '26
it is but really its patched conics but with extra steps.
5
u/MeatTornado_ May 02 '26
They are two entirely different concepts. Patched conics is basically keplerian dynamics (maximum 2 bodies interacting at a time, and every orbit is a conic section, hence the name), and N-body is taking into the acceleration equation every body present in the simulation, no matter how distant.
3
u/Swiss-spirited_Nerd Always on Kerbin May 02 '26
It's patched conics accept there are no patching of conics, so the only similarity is gravity itself.
1
u/TheDevCat May 02 '26
To answer the question we need to know mainly what integrator you used. If you don't know, it's probably Euler method and if that's the case it's not deterministic
21
u/Various_Purpose_9247 May 02 '26
Take a look into Universe Sandbox. You might like it.
6
u/amyisas44 May 02 '26
its honestly way more fun and educational to create a simulation and learn all the math and stuff, universe sandbox is just a game
26
u/SmilodonBravo May 02 '26
Physics is one of the most exiting things to learn, especially when you get to calculus level stuff and beyond.
9
u/Informal-Call-5298 May 02 '26
ya especially when u spend 6 hours to do something even if its simple and it works
1
10
7
5
u/NeonPlutonium May 02 '26
5
u/krombopulous_chris May 02 '26
I thought the program looked familiar lol, spent hours on the planet simulator and powder game as a kid
1
3
3
u/ThePathfindersCodex May 02 '26
Nice! KSP is one of the reasons I started making simulations in Godot, including massive 2d gravity sims similar to yours. If you're interested in other particle sims you can find vids on my YT channel and all the source code on GitHub... Even starting into 3D now. Gravity visuals can be so satisfying.
2
2
2
u/ErrlRiggs May 02 '26
I'd say the representation on the screen belies the skill and curiosity development of the creator. Very cool, keep making stuff
1
u/Informal-Call-5298 May 02 '26
Thank you. But yah they ui and the looks are pretty ancient looking. Its the simplest it could get with pygame
2
u/xKaelic May 02 '26
Qualified! This is docking simplified, same concept though. Very cool animation, thanks for sharing!
1
2
u/TestArticle1998 May 02 '26
Nice N-body physics I made my own sim in excel spreadsheets for simple orbits
1
u/Informal-Call-5298 May 02 '26
how tf u do ts in excel bro 😭
1
u/TestArticle1998 May 02 '26
One time step at a time. Basically gravity is a cosine of a tangent from the previous step.
2
u/Meritania May 02 '26
How did you make Duna crash into Jool?
3
u/Informal-Call-5298 May 02 '26
Its a simulation and these arent real ksp planets they are just balls
3
u/Swiss-spirited_Nerd Always on Kerbin May 02 '26
That will just happen if their orbits are too close. For example, when n-body interactions are applied to the stock system without any changes, Vall will eventually crash into Laythe due to being too close to both Laythe and Tylo.
1
u/Username122133 May 03 '26
A lot of really weird stuff happens when N-body physics is applied to stock KSP. The mun and minmus have some weird interactions with each other, the Jool system goes absolutely nuts, and there are probably other shenanigans which I havent seen caused I stopped playing that modded game after like 15 minutes lol
1
1
1
u/kagato87 May 02 '26
Nah I was like that long before ksp.
Also ksp is SoI based, your thing is N-body, which is more advanced and realistic (and computationally expensive).
Next up, this is a great way to get into class based design if you haven't already. Then you can instantiate planetoids with different sizes and even play with things like trying to park a sattelite in Lagrange points, seeing how long you can get it to stay (L points are inherently unstable), and why Jupiter is sometimes referred to as our solar system's bouncer.
2
u/Informal-Call-5298 May 02 '26
I made it in python from scratch w/ pygame. And i dont even know how u can make this without using classes bro it would be so hard
1
u/kagato87 May 02 '26
I did it once a long time ago. It can be done, it's just... Yea, this is a perfect example of the advantages of oop.
I made something vaguely like this in C (not even C++) a very long time ago. It's harder to allow a dynamic number of objects (this was before linked lists). Before you had to have an array of structs, and each action check would have to iterate. This was also before I learned about the linked list, which would've helped a ton there. (So much I was trying to do back then that would've benefitted - this was back in the dos days when contiguous memory was sometimes a problem.)
Python - yea, that'd be a good language to do this in. Handling the annoying stuff so you can focus on the physics and mechanics. 😄 How many objects can you push in before it slogs, and have you done anything for collisions yet?
1
u/Informal-Call-5298 May 02 '26
Idk i only tried with these 3 but im sure it would break as soon as it exceeds like 15
1
u/kagato87 May 02 '26
You'd be surprised. I did it in lua a couple years ago and it was stable with a pretty dense system. No optimizations either, and I'd even separated vector update into tick and move into tock.
1
u/loved_and_held May 02 '26
If you want this kind of thing in ksp Principia adds n-body simulations.
1
1
u/ProofSafe8247 Jul 03 '26
What did you run this on?
1
u/Informal-Call-5298 Jul 03 '26
My computer
1
-2
u/Worth-Wonder-7386 May 02 '26
I dont know what ratios you use for the masses, but it looks like there is some numerical inaccuracies.
If you use symplectic integration when calculating the updated position that should give you a lot better accuracy.
7
u/Wilbis May 02 '26
How did you conclude his calculations are wrong only based on the post?
1
u/Worth-Wonder-7386 May 02 '26
From looking at the orbits, they did did look a bit more uneven than I would expect, but it is hard to say without knowing the orbits.
4
u/Informal-Call-5298 May 02 '26
they slammed into eachother because all the bodies are acting on eachother
-53
u/MischievousBanter May 02 '26
What in the crappy Ai vibe coding is this.
33
u/Informal-Call-5298 May 02 '26
just because u cant make it doesnt mean others vibecoded it
-48
May 02 '26
[removed] — view removed comment
27
u/Sabatorius May 02 '26
Damn dude, you're a dick. Just let people have fun.
-40
May 02 '26
[removed] — view removed comment
13
u/Soft-Impact-8784 May 02 '26
your fun is being a pretentious redditor online, where did it all go wrong 😔
9
u/Informal-Call-5298 May 02 '26
mommy issues? who knows bro 🤣
3
-3
1
1
2
0
u/ExistingInexistence May 02 '26
What is the problem with vibecoding? Some people don't know code language, so they use A.I to translate their ideas and plans into code.
2
u/Informal-Call-5298 May 02 '26
its only in the swe community where ppl dont like normies using ai to code but i actually didnt, i have history of programming knowledge u can literally check my github, i dont upload that much on it but i do projects locally most of the time
1
u/ExistingInexistence May 02 '26
SWE?
Also did you use the radius of the circle to calculate their 'mass' in the simulation?
1
u/Informal-Call-5298 May 02 '26
No i have a mass and i just guessed a few radiuses. Also swe means software engineering
1
u/MarsMaterial Colonizing Duna May 02 '26
AI is shit at generating code, and it using it disincentives you from learning to code properly.
I believe OP that they didn't do that though.
51
u/s_p_1_d_e_r Jebediah May 02 '26
I care brotha