From the Lab
Detecting Non-Adjacent Particles to Avoid Crossing
Chujia Wei — June 10, 2013 - 10:31am
One of the features of ths project is to let all particles grow themselves yet not crossing with each other. Each particle is stored in array, and knows the distances with two adjecent neighbors. When two neighboring particles grow too close to each other, one of them will be killed to avoid collision. However, when two particles which are not neighbors about to cross, they cannot simply be alerted using this method.
We try to solve this with the idea below:
- Divide the whole screen into grid cells, the size of the grid cells can be changed as need. Each particle will remember the grid ID that it is currently in and register in that grid. If the total number of particles that have registered in the grid cell exceeds a threshold, the grid then is blocked and no new particles could enter. When a particle enters a new grid cell, it will: a) Check if this grid cell is still available. b) If the grid is still vacancy, update its current grid ID and register in the grid.
- There are two cases of collision: collide with particles which are also currently inside the grid; collide with the traces which are left by particles before.
- The possible solution to prevent the cases is: Get the information of other registered particles, check the distance with them, kill if needed; When there is a particle enter and leave without collisions, or two particles died, the grid cell is then marked as blocked, no more future particles can enter.
For example: As shown in figure below, when particle A enters this grid, it gets the information of B and C, thereby keeping checking the distance between each other. A, B and C can be killed all together when there is a death need.