Verlet Integration
I've been looking at verlet integration recently as a way to implement simple physics in my games. However, I'm not sure how it would be implemented. It's not so much the idea that confuses me, but rather how to turn that idea into code.
Does anyone have some simple code showing basic verlet integration (i.e. a constraint between two particles)?
It doesn't matter what language it is in, and if no code is available, a simple explanation on implementation would be appreciated.
Verlet step for one particle:
tmp=position;
position=2*position-oldposition;
oldposition:=position;
Simple wall (no bouncing):
if (tmp.x>1) {tmp.x=1};
Verlet distance constraint:
delta = x2-x1;
deltalength = sqrt(delta*delta);
delta *= (restlength-deltalength)/deltalength;
x1 -=delta;
x2 +=delta;
Approximation (just as good, half as costly):
delta = x2-x1;
delta*=restlength*restlength/(delta*delta+restlength*restlength)-0.5;
x1 -= delta;
x2 += delta;
tmp=position;
position=2*position-oldposition;
oldposition:=position;
Simple wall (no bouncing):
if (tmp.x>1) {tmp.x=1};
Verlet distance constraint:
delta = x2-x1;
deltalength = sqrt(delta*delta);
delta *= (restlength-deltalength)/deltalength;
x1 -=delta;
x2 +=delta;
Approximation (just as good, half as costly):
delta = x2-x1;
delta*=restlength*restlength/(delta*delta+restlength*restlength)-0.5;
x1 -= delta;
x2 += delta;
I hate to be rude, but that code doesn't help me very much. It's rather confusing, in my opinion... and having worthless lines like "deltalength = sqrt(delta*delta);" doesn't help my understanding.
Here's the presentation that introduced Verlet integration to many people -- it comes with very clear source code: http://www.teknikus.dk/tj/gdc2001.htm
Frankly it's a bit weird that you've heard of Verlet integration without having read or seen the paper, since it's almost certainly the reason you heard about it! I guess the people that told you about it failed to cite their sources. Jakobsen is even referenced in the wikipedia entry on verlet integration: http://en.wikipedia.org/wiki/Verlet_integration
Also, integration has nothing to do with constraints; you can enforce constraints between particles using many different methods, and in fact the simple "projection" method described by jakobsen can be used regardless of integrator (I've used it successfully with euler).
A simple explanation of verlet integration is that you approximate the current velocity using a backward difference: http://en.wikipedia.org/wiki/Finite_difference#Forward.2C_backward_and_central_differences
Finally, given that simply googling "verlet integration source code" produces a wide range of useful links, you should thank gagyi for responding at all!
Frankly it's a bit weird that you've heard of Verlet integration without having read or seen the paper, since it's almost certainly the reason you heard about it! I guess the people that told you about it failed to cite their sources. Jakobsen is even referenced in the wikipedia entry on verlet integration: http://en.wikipedia.org/wiki/Verlet_integration
Also, integration has nothing to do with constraints; you can enforce constraints between particles using many different methods, and in fact the simple "projection" method described by jakobsen can be used regardless of integrator (I've used it successfully with euler).
A simple explanation of verlet integration is that you approximate the current velocity using a backward difference: http://en.wikipedia.org/wiki/Finite_difference#Forward.2C_backward_and_central_differences
Finally, given that simply googling "verlet integration source code" produces a wide range of useful links, you should thank gagyi for responding at all!
Sorry, I'll admit I was rude. Thanks for your reply Gagyi, I really did appreciate it... it just confused me a bit.
Thanks for the links Raigan, I'll check them out. I had heard of verlet integration a bunch of times from different resources, yet I have not seen that paper before, as it seems to be exactly what I need.
Thanks again for the help.
Thanks for the links Raigan, I'll check them out. I had heard of verlet integration a bunch of times from different resources, yet I have not seen that paper before, as it seems to be exactly what I need.
Thanks again for the help.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement