-1
$\begingroup$

I'm programming a gravity system, based on this answer, and I've also tried this approach.

Everything is working fine, but I want the objects to pass through each other without any collision and to keep an harmonic motion,. To see what I mean, try placing two planets on this simulation with 'Merge off'.

However, on my implementation, there's a point in which the bodies are very close and they make a huge force on each other, getting them into unexpected places.

I guess this can be solved by using adaptative time steps and/or trying different integration approaches. However, I'm sure there has to be a simple, hacky way to get the harmonic behaviour descrived above.

Any help?

$\endgroup$
  • $\begingroup$ Your second link should be your approach. Do you know the physical meaning of the parameter "$\epsilon$" in that equation? It is (roughly) the distance at which your force (artificially) stops depending on distance and becomes constant. My guess is your $\epsilon$ is too small. Try using a larger value of $\epsilon$ and see if it works. $\endgroup$ – pela Dec 6 '16 at 12:03
  • $\begingroup$ Well, thank you a lot! I thought it was supposed to be a value like 0.01. I tried using the radius of the body and it works pretty well. Just a matter of tuning it now, I guess. $\endgroup$ – Knexator Dec 6 '16 at 15:21
  • $\begingroup$ You're welcome. In case you're using Eulerian integration rather than Leapfrog, you might wanna change that as well, since it's just as easy and much better. This answer has a Python version that should be translatable to other languages. Note though that the rest of the code in that particular answer is rather specific, in that it calculates the trajectory of a planet orbiting a star that suddenly starts to move. $\endgroup$ – pela Dec 6 '16 at 21:08
  • $\begingroup$ This seems to be a programming issue, which ought to be asked in Stack Overflow. $\endgroup$ – sammy gerbil Dec 6 '16 at 21:22
0
$\begingroup$

Bodies being very close and imparting huge forces on each other ultimately means huge speeds. But this implies very small time of passing through (if you take this approach; in general this is an ill-defined situation). Thus at some distance, when the particles are sure to pass through each other (this is in the case of zero angular momentum), you can just move them as if they have passed already. You may just want to adjust the time when they appear at the new position by estimating how long it would actually take (two-body problem is exactly solvable).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.