Advertisement
rfmonk

particle_simulator.py

Mar 17th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. class ParticleSimulator:
  2.  
  3.     def __init__(self, particles):
  4.         self.particles = particles
  5.  
  6.     def evolve(self, dt):
  7.         timestep = 0.00001
  8.         nsteps = int(dt / timestep)
  9.  
  10.         for i in range(nsteps):
  11.             for p in self.particles:
  12.  
  13.                 # 1. calculate the direction
  14.                 norm = (p.x ** 2 + p.y ** 2) ** 0.5
  15.                 v_x = (-p.y) / norm
  16.                 v_y = p.x / norm
  17.  
  18.                 # 2. calculate the displacement
  19.                 d_x = timestep * p.ang_speed * v_x
  20.                 d_y = timestep * p.ang_speed * v_y
  21.  
  22.                 p.x += d_x
  23.                 p.y += d_y
  24.  
  25.                 # 3. repeat all three steps
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement