Gravity Simulator
nowykurier.com
nowykurier.com
There are a couple of variations, and some tweaks like the ships accelerating perpendicular to the planets so they don't crash land.
I have a non-combat version in 3d. Now I know what mine is missing. https://www.youtube.com/watch?v=73O8aDN41sU
That's be a toroidal spacetime surface, wouldn't it? Would gravitational influence also have to "loop around" the borders?
If not, you might get some very interesting effects if a mass is near the edge of the map.
https://i.imgur.com/j3YwI5y.png
That was me trying to have a small particle making an 8-shaped path around two bigger ones that would be sufficiently far apart to not interact too strongly with each other. Of course, when the small particle went between the two bigger ones, it shifted their position a tiny bit, but sufficiently for those two to start very slowly moving towards each other, while the small particle was headed straight to the up-right direction. But when the two bigger particles became close enough to finally meet and become one single huge particle, it attracted back the small one, which since then goes back slowly to the huge particle only to shift it a bit and be "relaunched" by it for a new lap. The system seems to be totally stable that way.
Update: https://i.imgur.com/heHekdc.png
This kind of path is called a free return trajectory and was used in the Apollo program lunar missions. The trajectory is not periodic, ie. it doesn't repeat more than once. The trajectory around the earth takes less time than lunar period ("month") so when the craft goes back up, the moon has moved on. You might be able to construct a planet-moon system with an m:n resonance in the orbital periods of the moon and the craft so that the tracjetory is periodic.
Free return trajectories are used in manned space flight to guarantee that the craft and crew return to earth if a failure prevents from entering lunar orbit.
Oh, well. Here's my gravity simulator -- it uses JavaScript, no flash required:
They seem to have corrected the sentence now: "particle radius is log of mass".
Wow, your simulator is much nicer, plus a great article about it to boot! You should add an option to play cosmic billiard, that's probably the main appeal of the flash simulator :)
> They seem to have corrected the sentence now: "particle radius is log of mass".
It's still wrong. Here's a graph comparing mass = e^radius (the reciprocal of radius = log(mass) ) versus mass = radius^3:
http://i.imgur.com/XkVFgIH.png
My point is that the two functions have a different behavior, the absolute values generated aren't very important compared to that. For solutions to f = G m1 m2 / r^2 where both bodies are computed, this will produce results wildly different than reality. (If only one body is computed, for example against a much larger parent body mass, the satellite mass stops making a difference.)
> You should add an option to play cosmic billiard, that's probably the main appeal of the flash simulator :)
Nice idea. I was more interested in portraying the solar system using real planetary masses and real physical constants. Still, it's a nice suggestion.
That's the thing with those kind of simulators (or, actually, with reality), your reference has no relation to the center of mass of the system.
Of course, if you "were there" the reference would be the center of mass, like the reference of the solar system is "The Sun" (or a point inside it)
https://en.wikipedia.org/wiki/Barycentric_coordinates_(astro...
If you limit yourself to looking at the position of one body with respect to another, the orbit will be an ellipse. A circular orbit is simply a special-case ellipse with an eccentricity of zero. This is true for any two orbiting masses -- from the perspective of either of them, the other body's orbit will be an ellipse. And yes, it's always with respect to the common center of mass.
Interestingly, mostly because of Jupiter, the solar system's common center of mass can sometimes lie outside the sun.
https://en.wikipedia.org/wiki/Barycentric_coordinates_(astro...
Likewise, two bodies that are not bound will follow hyperbolas in the center of mass frame.
Or parabolas, which also represent unbound solutions. In an orbital system, a parabolic trajectory represents escape velocity (exactly), a solution in which the escaping body's velocity is in progressive decline, and that reaches zero at infinity.
http://en.wikipedia.org/wiki/Binary_star#mediaviewer/File:Or...
OP: This is an amazing tool to learn the sensitivity of dynamical systems to initial conditions. Well done!
It took a little bit to generate this one.
Also, how hard would it be to set an initial state of our current solar system? Teachers could set up scenarios for students to interact with, and allow students to collaborate.
Maybe as simple as an output/input of textual data for saving & restoring state? i'd love to try model our current solar system, and see if i can get something to mars with just an initial trajectory.
see:
http://en.wikipedia.org/wiki/Interplanetary_Transport_Networ...
Moreso, best to stick with terms that are acceptable to people of all cultures and backgrounds. The word 'fucking' may be a light-hearted slang to a 20 year old american, but it may just be offensive to someone older living in the UAE.
Professionalism, though not perfect, does in fact help in making people from various background agree and understand good ideas by being austere, simple and well-defined.
Personally I prefer to just throw a fourth order Runge–Kutta (RK4) at things and normally that's more than good enough.
List of reading:
http://gafferongames.com/game-physics/integration-basics/
http://en.wikipedia.org/wiki/Euler_method
http://en.wikipedia.org/wiki/List_of_Runge%E2%80%93Kutta_met...
http://mathworld.wolfram.com/Runge-KuttaMethod.html
http://en.wikipedia.org/wiki/Linear_multistep_method
http://en.wikipedia.org/wiki/Bulirsch%E2%80%93Stoer_algorith...
In the context of gravity simulation, I must point out that while Runge-Kutta/RK4 is good enough for a lot of stuff but it has a tendency to dissipate energy. It's not very good in a simulation where the conservation of energy is important. Run a simulation long enough and the orbits will eventually shrink.
If scientific accuracy is required, gravity simulations are usually done with "symplectic" integrators (which don't "lose" energy) and the equations of motion are written using Hamiltonian mechanics. There are symplectic variants of Runge-Kutta too.
In an exercise work for a celestial mechanics course, I wrote an n-body simulator using a dissipative Runge-Kutta method (because it was good enough for that, and the exercise was about using RK methods). Simulating an exoplanet system (HR 8799), the orbits were stable and 100 year simulation gave near perfect orbits. After 1000 years, there orbits were a bit smaller and after 10000 years, they had lost a fourth of the initial energy. This was done using one day timesteps.
I can't speak to the linked simulator, but gravitational calculations are relatively simple -- they represent the solution to a numerical differential equation that, in small slices of time, solves:
f = G m1 m2 / r^2
Where:
f = force, Newtons
G = Universal gravitational constant: http://en.wikipedia.org/wiki/Gravitational_constant
m1 = mass of body 1, kilograms
m2 = mass of body 2, kilograms
r = distance between m1 and m2, meters
Here's my simulator, plus (further down the page) a complete description of the math. My simulator uses HTML5 and JavaScript:
http://arachnoid.com/orbital_dynamics
> I wasn't aware it was possible to run such a simulation on flash because each body results in 6x more calculation.
It's more accurate to say that the total computing time required changes as the square of the number of modeled bodies. That's worse than 6x, by the way, for a sufficient number of bodies. One solution is to use a large central mass and only compute the paths of some satellites with respect to the central mass, not with respect to each other.
The calculations that impress me (and I do a lot of this kind of math) are the cosmological modeling of galactic clusters of hundreds of thousands of stars, all interacting with each other, with no central mass to stabilize things. This requires a supercomputer and many hours of online time.
> Is this like plugging in the masses into a single equation?
No, because for more than two bodies, there's no closed-form solution (this is called the "three-body problem"). Solutions must be arrived at numerically. When NASA wants to compute where to land a spacecraft on Mars, they have to use numerical methods -- very good ones, but numerical methods.
Here's a snapshot of object locations in the inner solar system:
http://ssd.jpl.nasa.gov/?ss_inner
There are a lot of challenging problem areas: rendezvous with small bodies (very irregular gravity fields), mission trajectory design, operations planning for flybys in the presence of, say, camera pointing constraints.
(@lutusp knows this already -- I'm putting it here just for interest.)
http://jbochi.github.io/planets/ http://suki.ipb.ac.rs/3body/
The first one was back in 1999, I wrote one with 13h[1] graphics for DOS (Borland Turbo C++), and to make it more fun, I used flat sprites to represent the objects (so the objects progressed from being rocks to asteroids to planets - with the largest sprite I used being an image of Jupiter).
A few years later, I rewrote it in OpenGL (using the GLUT library) for a class. It worked much better (and of course the hardware was much faster too).
I had always planned rewriting the physics engine to use Barnes-Hut, but never got around to it, so it always ran at N^2.
Anyway, for the curious, the code is up on Github amongst my collection of other old garbage stuff from back in the day: https://github.com/choptastic/OldCode-Public/tree/master/Gra...
(To reproduce, use a really big stable mass (either enter it by hand or use the OMFG button and click several time at the same position without moving your mouse) and launch at fast speed a tiny particle in an approximately tangent direction of a circle centered on the big mass.)
I didn't know that Moiré pattern could appear on a screen "without" a second grid (or rather, I didn't realize that the pixels of my display could serve as the second grid, which is kind of obvious now that you said it).
New screenshots: https://imgur.com/a/7W9FI :)
EDIT: oh hey, I found a binary. https://www.dropbox.com/s/ihfqnzjaxhtskwt/Screenshot%202014-...
I was trying for the effect you see in high school physics videos. My approach was to use a plane geometry mesh and apply a vertex displacement shader, but never quite got it to look or perform how I wanted.
-Saving your setting
-Undo-ing
-Auto generate small object in perfect circle orbit around larger object, and generate sun-earth-moon system
-Export setting to other people
-Allow to numerically finetune locations and velocities
-Don't ruin the trails when dragging
-Make it run faster, especially with trails enabled
-etc... :)
EDIT: Gee, when will Hacker News finally support newlines properly?As a person who actually learned basic mechanics by writing video games I do believe that "you ain't understood nothing until you know how to teach it to a computer". Trying to express knowledge in (working) code is a great exercise that mercilessly catches even tiny holes in one's understanding.
say you add 3+ equal mass objects without a velocity and they all collide with each other without "missing or orbiting" one another. Sometimes the final mass will have a velocity.
It would seem like it should not have a velocity because it would be canceled out. What am I missing? Where is this energy coming from?
But in a numerical simulation, usually what happens is that three bodies on a collision source approach one another but, because of the limitations of numerical differential equation solving, suddenly fly away from each other in a rather non-physical way, and with more energy than they had to begin with.
The tl;dr: most of the funny effects in a simulator arise from the limitations of numerical simulation methods, and many of those aren't representative of real physics.
Question.. How big is the frame? I create two objects and they went out of frame. Then I create 2 more but a bit bigger ones and after 2-3 minutes I see those two objects coming back and it looks good too :D .. check it out http://imgur.com/IBYeysm
After all, if a particle leaves the viewport, it doesn't affect the particle count readout at all.
I assume if things move far enough, there would probably be interesting floating-point precision errors, but I'd imagine that would take quite a while.
Using the rapid-click feature on my mouse to place a dense circle outline: http://i.imgur.com/14IN5pi.png
http://www.masswerk.at/spacewar/inside/insidespacewar-pt6-gr...
As for this app it would be awesome if you could zoom out -- I find most of my stable(-ish) orbits are very long and at very large mass sizes, so it would be good to see their entire orbits.
a funny thing to do is to try to put those into a stable orbit
See [1]. Especially slides 11 and 12 may be of interest.
[1] http://www.astro.sunysb.edu/phy277/lect30.pdf
As a sidenote, there are better integration schemes, but all of them will have some error because we discretize the system.
But in general, you can control the error and make a trade-off between computing time and accuracy. You would select a timescale over which you want the error to be below some value, and then only consider the simulation valid until then.
Thanks
That's already what happens here.
> Particle radius is log of mass.
Wouldn't it make more sense for the radius to be the cube root of mass (assuming uniform density)?
His app is being used in schools.
http://i.imgur.com/roHx3wi.png
Really nice tool.
[1] In fact if all initial positions and velocities lie in the same 2d plane, all trajectories would also lie in this plane. Since the interface only allows one to set such initial conditions, I am fairly confident that the simulation is 2d only.
http://newton.azurewebsites.net/
Pure Javascript using Sylvester.js for Math.
took a while for me to work out though.
There has to be a game in this somewhere...
> Error #2046
I did "rm -rf ~/.macromedia/Flash_Player/" but still get Error #2046....
turn on combine mass on collision
add galaxy in middle
watch the creation of a solar system :)
[1] https://bugzilla.mozilla.org/enter_bug.cgi?product=Firefox&c...
What do you need Flash for?