[quote author=Clotaire link=topic=1186.msg7507#msg7507 date=1289386681]
[quote author=lookang link=topic=1186.msg4649#msg4649 date=1251859495]
http://www.um.es/fem/EjsWiki/Main/ExamplesMultipleCollisions by Francisco Esquembre is possibly a suitable example for u to study and discuss on.

[/quote]
I check your code when there are some overlap, you ask the program to give the ball a new random velocity. it is right?
[/quote]
no. it is not random at all.
[code]//System.out.println ("Collision between "+collision1 +" and "+collision2);
//System.out.println ("at x[1]= "+x[collision1] +" and x[2] = "+x[collision2]);
double deltax = x[collision2]-x[collision1];
double deltay = y[collision2]-y[collision1];
double distance = Math.sqrt(deltax*deltax+deltay*deltay);

double rx=deltax/distance, ry=deltay/distance; // Unit vector joining centers
double sx=-ry, sy=rx; // Vector ortogonal to the previous one

double vr1=(vx[collision1]*rx+vy[collision1]*ry), vs1=(vx[collision1]*sx+vy[collision1]*sy); // Projections for disk 1
double vr2=(vx[collision2]*rx+vy[collision2]*ry), vs2=(vx[collision2]*sx+vy[collision2]*sy); // Projections for disk 2

double vr1d=( 2*mass[collision2]*vr2 + (mass[collision1]-mass[collision2])*vr1 )/(mass[collision1]+mass[collision2]); // New velocity for disk 1
double vr2d=( 2*mass[collision1]*vr1 + (mass[collision2]-mass[collision1])*vr2 )/(mass[collision1]+mass[collision2]); // New velocity for disk 2
// Undo the projections
vx[collision1]=vr1d*rx+vs1*sx; vy[collision1]=vr1d*ry+vs1*sy;
vx[collision2]=vr2d*rx+vs2*sx; vy[collision2]=vr2d*ry+vs2*sy;
[/code]