Particle System




A. The procedure animate() is define in ParticleMain.cpp
   There is another procedure animate2() which double check the
   correct result is return.

B. In my system the user is able to adjust lambda, r0 and a factor
   that limit the magnitude of force. Since it is possible that
   when time step is not small enough, two particle would be
   very close and 1/r will got pretty big. This cause the system
   very unstable.

   r0 is default to be the initial particle distance in grid.

   Gravity is added in the system which can be turn on/off via
   the 'Add Gravity' checkbox.

C. The floor is define as bottom of window (y = 0). There
   are two objects in the scene. One is a square on the floor,
   another is a rectangle floating in the air. In additional
   ceiling (y = 1) , left (x = 0) and right (x = 1) wall boundaries
   are added to contain particle if necessary.

   There are 2 checkbox for these. 'Add obstacles' is used to
   turn on/off the square and rectangle obstacle.
   'Add boundary' is used to turn on/off the left, right and
   ceiling.

D. For floor, collision detection is check for y < 0. The particles
   is projected to the closest outside point for new position.
   If the velocity just computed (from new force) dot plane normal
   is positive, it is used as response velocity.
   Otherwise, the old velocity vertical component (to plane normal)
   is reverse, multiple by friction, and add back to horizontal
   component to form new response velocity.

   For Rectangle, the point containment test is used. To compute the
   response. We need to figure out which one of 4 plane should use
   for collision response.

   Given a rectangle, it divide the space into 9 parts with itself
   in the center. If the old position (i.e. the one without collision)
   lie in the top/bottom/right/left region we know which plane to use.
   If the old position lie in the four corner regions. We use the
   current position to see which 2 planes in the corner is closer
   and select that one for collison response similar to floor.

   My system allow user to adjust friction in GUI through friction
   edit box.

E. The procedure handleCollision() is written in ParticleMain.cpp  
   Besides the input & output for position/velocity. There are 2
   more arguments. One to specify friction and another to specify
   a vector of Shape2D as obstacle. There are currently 2 Shape2D
   implementation: Rect.cpp and Plane2D.cpp. Both implement the
   collision, response and intersect function from base class.

F. The user is able to pick a particle in the system (highlight by
   yellow) and drag the particle around. A spring is attach to it
   with default stiffness, damp and natural length (=0). They all
   are adjustable through the edit box GUI.

G. The demo start with 3x3 grid and gravity, boundary, obstacles on.

H. The scene is partition into 2x2 grid to store particle. The size
   of grid is 2*r0. Each grid store a vector of particles and list
   of obstacles (e.g. floor, left wall, square on floor ..) fall into
   it. Only the 8 neighbors grid and itself is considered when computing
   forces. As a result it run in nearly linear time and can support
   100x100 particles with > 30fps. To show the partition, check the
   'show partition' checkbox. Different paritition will show particle 
   in it with different color.

I. The number of particle is adjustable in grid size edit box.
   The user can also adjust the timestep of the simulation.  
   Note that all attributes, except timestep, add gravity & show partition,
   will not take into effect unless user press the Restart button.

   Note that for larger grid size, you need to set bigger gravity constant
   in the editbox. For 3x3 I use 0.1, for 30x30 it is recomment to use 9.8.

   The system will display current frame rate and time.

   There are 14 attribues in my partition system that user can play around
   and produce a variety of effect.

Download program

Have fun !