All pastes #10430 Raw Edit

Unnamed

public text v1 · immutable
#10430 ·published 2005-04-27 16:23 UTC
rendered paste body
    public int detectCollisions(){
		boolean particleCollisionRecorded = false; // to avoid collisions of multiple particles
		int collisions = 0;

		for(int i=1;i<P.length;i++) // loop through all particles in the ensemble
		{
			particleCollisionRecorded = false;
			for(int j = 1;j < i;j++) // loop through all unchecked particles
			{
				if(CollisionTable[i][j] == -1) // update whether particles are restricted from colliding
				{
					if( !Particle.withinDist(P[i],P[j],3*(P[i].getCollisionRadius() + P[j].getCollisionRadius())) )  CollisionTable[i][j] = 0;
				}
				if( ((CollisionTable[i][j] == 0) && (P[i].CollisionPossible(P[j]))) && !particleCollisionRecorded ) //  if a particle isnt restricted, hasnt already collided this loop and is near enough, let it collide
				{
					CollisionTable[i][j] = 1;
					collisions++;

					particleCollisionRecorded = true; // prevent this particle colliding again this loop
				}
			}
		}
	
		int j;
		int i;
		int jposcol= -1;

		for(i=1;i<P.length;i++)
		{
			for(j = 1;j < i;j++)
			{
				if( CollisionTable[i][j] == 1 )
				{
					jposcol = j;
					break;	
				}
			}

			if( jposcol != -1 )
			{
				for(int k = 1;k < P.length;k++)
				{
					if( (k != i) && (CollisionTable[k][jposcol] == 1) ) 
					{
						CollisionTable[k][j] = 0;
					}
				}
			}
		}
		
	
		// System.out.println("table for detection");
		// this.printCT(30);
	return collisions;
    }