Hi,
First: congratulations on a great package!
I am a physicist, and would like to use Chipmunk Physics for research simulations. One of the main cases of interest, however, is that of elastic collisions, where energy should be conserved. I notice that setting elasticity=1.0 is not advised in the documentation, "... due to inaccuracies in the simulation ...".
Practically speaking, if I set a couple balls to bounce around randomly in a complex environment (bounded by segments), I don't see too many problems if the time step is kept low, and if I don't simulate for too long. However, if I monitor total energy for 3 million time steps (with dt=0.01, velocities typically magnitude 10), I see it creep up to 6% increase (see graph below).
My questions are:
- anything more precise to be said on use of elastic collisions, when they may be expected to work, when they shouldn't be expected to work? Rummaging around a bit indicated there was some discussion on this on a google code page that no longer exists...
- will current work on collisions (that I have seen referred to on the bugs forum) make elastic collisions any more stable?
energy conservation and elastic collision
-
- Posts: 2
- Joined: Wed Feb 13, 2013 4:35 pm
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: energy conservation and elastic collision
Well, it's not so much a bug as it is the solver trading accuracy for speed. It's an iterative solver that uses the previous step's impulse solution as a starting point for the next. This is optimizing for stable contacts, as the previous step's solution is generally very close to the solution needed for this step. This does cause a slight issue with collisions though, as the first step that two bodies begin colliding produces a very large impulse. The next step should produce a very small impulse or possibly none. Because it starts with the large impulse from the step before (instead of 0), it converges towards the solution and ends with one that is slightly too high.
There are a couple things you can do to minimize the error though. Setting the iterations property of the space to a higher number will allow it to converge much more closely on the actual solution. Using smaller timesteps may also help, but not as much as increasing the iterations. Lastly, there is the collision persistence property of a space. It sets how many steps the collision impulse should be retained for. I think it defaults to 3 (I lied above slightly). Without looking at the code I'm not convinced that a value of 0 will actually disable the persistence though. I think it might process things in the wrong order to allow it to be disabled entirely.
There are a couple things you can do to minimize the error though. Setting the iterations property of the space to a higher number will allow it to converge much more closely on the actual solution. Using smaller timesteps may also help, but not as much as increasing the iterations. Lastly, there is the collision persistence property of a space. It sets how many steps the collision impulse should be retained for. I think it defaults to 3 (I lied above slightly). Without looking at the code I'm not convinced that a value of 0 will actually disable the persistence though. I think it might process things in the wrong order to allow it to be disabled entirely.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 2
- Joined: Wed Feb 13, 2013 4:35 pm
- Contact:
Re: energy conservation and elastic collision
Thanks very much for your thoughtful reply.
I will try your suggestions and report back.
I will try your suggestions and report back.
Who is online
Users browsing this forum: No registered users and 18 guests