Created
May 20, 2010 23:01
-
-
Save nervoussystem/408241 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //save previous particle forces and velocities | |
| ArrayList prevForces = new ArrayList(); | |
| ArrayList prevVelocities = new ArrayList(); | |
| for(int i=0;i<particles.size();++i) { | |
| Particle p = (Particle) particles.get(i); | |
| prevVelocities.add(p.velocity); | |
| prevForces.add(p.force); | |
| } | |
| //compute estimate | |
| for(int i=0;i<particles.size();++i) { | |
| Particle p = (Particle) particles.get(i); | |
| p.position += deltaT*p.velocity; | |
| p.velocity += deltaT*p.force/p.mass; | |
| } | |
| computeForces(); | |
| for(int i=0;i<particles.size();++i) { | |
| Particle p = (Particle) particles.get(i); | |
| PVector prevV = (PVector) prevVelocities.get(i); | |
| PVector prevF = (PVector) prevForces.get(i); | |
| p.position += deltaT*(p.velocity+prevVelocity)/2.0; | |
| p.velocity += deltaT*(p.force+prevForce)/p.mass/2.0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment