1 package prefuse.util.force; 2 3 import java.util.Iterator ; 4 5 13 public class EulerIntegrator implements Integrator { 14 15 18 public void integrate(ForceSimulator sim, long timestep) { 19 float speedLimit = sim.getSpeedLimit(); 20 Iterator iter = sim.getItems(); 21 while ( iter.hasNext() ) { 22 ForceItem item = (ForceItem)iter.next(); 23 item.location[0] += timestep * item.velocity[0]; 24 item.location[1] += timestep * item.velocity[1]; 25 float coeff = timestep / item.mass; 26 item.velocity[0] += coeff * item.force[0]; 27 item.velocity[1] += coeff * item.force[1]; 28 float vx = item.velocity[0]; 29 float vy = item.velocity[1]; 30 float v = (float)Math.sqrt(vx*vx+vy*vy); 31 if ( v > speedLimit ) { 32 item.velocity[0] = speedLimit * vx / v; 33 item.velocity[1] = speedLimit * vy / v; 34 } 35 } 36 } 37 38 } | Popular Tags |