Playing with gravity, problem

Started by
2 comments, last by taby 13 years ago
Hi all,

I made this small gravity testbed to play around with:

http://labs.sjmulder.nl/ohgravity
source at: http://github.com/sjmulder/ohgravity

What I was expecting/hoping to happen was for the bodies to do some buzzing about until finally collapsing. However, this isn’t really happing, instead the bodies slowly get more and more energy. Do they not know they need to observer the laws of nature?

In all seriousness, what seems to happen is that when two bodies get really close together they gain a whole lot of momentum, more than is recovered from the mutual attraction as they fly off.

Any ideas on where to start looking to fix this?

edit: best visible with two bodies: http://labs.sjmulder.nl/ohgravity/#num=2
Advertisement
Its been a while since my physics class so I could be wrong, but for what reason do you expect your system to collapse? There's not any friction between the particles, so I would assume that the system should just stay at a stable state forever.

The second law says that the entropy must increase or remain the same, and the latter seems to be the case in your system.

Leaving it running for a long time seems that the particles veeeery slowly increase in velocity, but this could just be a mathematical rounding error, given that I don't expect they should ever slow down.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
I don't know if this is a separate problem, but it looks like there's no collision detection - when an asteroid gets pulled into earth, the resulting collision 'merges' the two rocks into one body. If there was no collision, then the asteroid could zip right through the other side and keep going, with a very large slingshot effect.
See this post about adding a repulsive term at short distances... this may help you to get what you want.

And like Hodgman (a brilliant person) says, you might want to manually add "collision" detection. The problem is that your gravitational sources are points, singular -- as r goes to 0, 1/r^2 goes to infinity. Bad news.

This topic is closed to new replies.

Advertisement