9 ms·
Show HN: Harmony of the Spheres – Gravity Simulator
- budhajeewa 8y agoCouldn't try this as I am phone. But I do find gravity simulators oddly satisfying.
- the_happy_koala 8y agoMy CSS skills aren't what they should be, but I'm going to try to make a mobile friendly version of the simulator at some point once I know more about flexboxes, media queries and what have you.
- jasmcole 8y agoFor long simulations I'd like to increase the timestep, but then RK4 becomes less accurate. For the n body problem, do symplectic integrators work well?
- alkonaut 8y agoYes, the difference is enormous. Use e.g Verlet integration and it’s much more stable. That it’s also much simpler and more elegant RK4 is an added bonus.
- the_happy_koala 8y agoIf for whatever reason you have time and would like to make a contribution, I think doing so should be quite easy as I think you'd just have to subclass the Euler class. You can get an idea of how to do this by looking at how I did it with the RK4 subclass (https://github.com/TheHappyKoala/Harmony-of-the-Spheres/tree/master/src/js/Physics/Integrators https://github.com/TheHappyKoala/Harmony-of-the-Spheres/tree...). If not, I'll add Verlet integration myself one of these days, but right now I'm working on introducing a particle system so that I can simulate the rings of Saturn (the particles will feel the gravity of all the masses in the simulation, but they won't exert a gravitational force on the other particles and masses in the simulation; this way you should be able to have fun distorting the rings of Saturn with a celestial object of your choice).
- the_happy_koala 8y agoI'm working on implementing an integrator with an adaptive time step, so that the time step is high when masses are far away from each other and just coasting, but low when they get close to each other and interesting things happen; think the orbit of a comet getting altered as it encounters Jupiter after a long journey from the Oort cloud. As things are now, such a scenario would be painfully slow to simulate if you want to maintain accuracy, but if you speed up the time step, nothing remotely realistic will come out of the simulator... So good point, and I hope I'll be able to cobble together a solution soon enough :D. As for symplectic integrators, I'm not sure they stay symplectic if you alter the time step, but I could be wrong!
- xixixao 8y agoThis actually works suprisingly well on my phone! Well done, love being able to modify masses mid-scenario and see the whole system disintegrate.
- the_happy_koala 8y agoThankie!
- pavel_lishin 8y agoAny idea why Juno appears to be pre-programmed to start with a pretty huge radial outward velocity?
- rzzzt 8y agoI think the simulation is running in 3D space. You can modify the position and velocity of each body in the "Modify Masses" panel and there are three components to adjust.
- the_happy_koala 8y agoHi Pavel! Every body in the simulation start out with a set of initial position and velocity vectors. For the solar system scenarios, I got these vectors from NASA JPL's Horizon System (https://ssd.jpl.nasa.gov/horizons.cgi#top https://ssd.jpl.nasa.gov/horizons.cgi#top), so the orbit of Juno that you are observing is its actual orbit... Its eccentricity (the extent to which the shape of the orbit departs from a perfect circle) is extremely high; at its closest point, the orbit brings Juno right above the cloud tops of Jupiter, and at its furthest point Juno finds itself beyond Themisto (one of Jupiter's irregular Moons which I should perhaps add to the scenario). Juno was meant to have a less eccentric orbit, but as technical problems were encountered when they were going to fire Juno's thrusters to reduce the eccentricity of the orbit, NASA played it safe and let Juno stay on its eccentric orbit. One of the advantages of this is that Juno only spends a very short amount of time in Jupiter's insanely powerful and to a spacecraft damaging magnetic field, so the technical mishap is probably one of the reasons JunoCam is still operating and giving us beautiful images of Jupiter's swirling clouds! Here's a gif from WikiPedia showing how stretched out Juno's orbit is https://en.wikipedia.org/wiki/Juno_(spacecraft)#/media/File:Animation_of_Juno_trajectory_around_Jupiter.gif https://en.wikipedia.org/wiki/Juno_(spacecraft)#/media/File:.... Sorry for the long rant, but I find these things to be awesomely fascinating.
- pavel_lishin 8y ago> Sorry for the long rant You've got nothing to apologize for, that was fascinating! I knew its orbit had some eccentricity, but I didn't know it was that much!
- enriquto 8y agoI would love if kerbal, simplerockets and the like used this realistic gravity simulation. The piecewise conic approximation is great, but after a few weeks of playing it gets very tiresome and too obviously limited...
- magnetic 8y agoHave you looked into Orbiter 2016? http://orbit.medphys.ucl.ac.uk http://orbit.medphys.ucl.ac.uk - I recently learned about it and wanted to try it after playing with KSP, but it seems it's Windows only.
- rzzzt 8y agoBach's Air is now permanently ingrained into my brain, paired with the soothing rumbling of booster rockets.
- the_happy_koala 8y agoOrbiter, like magnetic pointed out, is probably what you're looking for! That having been said, I plan to introduce spacecraft that can be controlled by the user in a realistic manner at some point, although I want to get the physics (thrust, attitude control and so on) right before introducing this feature. If you check back in a couple of days there will be a simulation of the up and coming Dear Moon mission (the plan, to send a bunch of artists in a free return trajectory around the Moon, concocted by a Japanese billionaire that will be executed by SpaceX).
- YaxelPerez 8y agoYou might be interested in this mod for KSP which adds n-body physics: https://github.com/mockingbirdnest/Principia https://github.com/mockingbirdnest/Principia
- enriquto 8y ago> You might be interested in this mod for KSP which adds n-body physics ...aaaand there goes all the work I was planning to do on the winter holidays!
- the_happy_koala 8y agoI just realized that I'm yet to properly introduce myself to you folks; name's Darrell (the Happy Koala - I love koalas the way other people seem to love cats!). I'm a self taught developer and the project this thread is concerned with is actually the reason, pretty much, I started dabbling with code. If you want more of a background, you can check out an article I wrote over at Medium about the evolution of this project and how it led to me becoming a web developer - https://medium.com/@darrell.arjuna.huffman/how-an-interest-in-physics-led-me-to-a-new-career-in-web-development-f863ea118099 https://medium.com/@darrell.arjuna.huffman/how-an-interest-i... (please bear with any spelling or grammatical mistakes as English is not my first language). I'm still very much of a junior empty stack developer, but I love coding and intend to continue doing so, so hopefully we'll have lots of interesting discussions here on Hacker News in the future! Having said that, have a nice start to the week!
- PaulHoule 8y ago(I used to simulate classical mechanics for a living, so...) It's pretty good except it runs a lot slower than it has to. The default step size is too small for most cases so you have to wait a long time for the planets to move around. When I tried increasing the step size with the slider I'd inevitably increase it too much and the planets would fly away. Personally I always use RK4 and similar algorithms with adaptive step size, mostly because it is a pain to tune the step size by hand https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods#Adaptive_Runge%E2%80%93Kutta_methods https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods#Ad... also if planets are passing close to each other you may need a shorter step when you are close and a longer step when you are far away. RK4 or RK5 with adaptive timesteps will make your demo much better with very little work. There are methods that use higher order derivatives and other tricks to take large steps, for instance I like this method https://github.com/alexrudy/bsint https://github.com/alexrudy/bsint If you were integrating the solar system for millions of years you would want a symplectic integrator. https://en.wikipedia.org/wiki/Symplectic_integrator https://en.wikipedia.org/wiki/Symplectic_integrator this might not be more accurate than another integrator but it will preserve phase space area which makes it possible that the long-term dynamics will "look like" the real long-term dynamics. (Otherwise it certainly won't!) If it were me in cases where there is a central large mass I would integrate in spherical or cylindrical coordinates, probably I would use a predictor-corrector method.
- gerdesj 8y agoI've just spent some time on this. The Oumuamua scenario is superb - that alone is worth every penny. Thank you.