Hi all.
collision is a problem when I do the formula and the balls is stopped. do not understand why they stopped. I have the following code.

double  x1=ball.center.x,  y1=ball.center.y,  x2=balltwo.center.x,  y2=balltwo.center.y,
vx1=ballspeedx,  vy1=ballspeedy,  vx2=balltwospeedx,  vy2=balltwospeedy;

double dx = x2-x1, dy = y2-y1;
// where x1,y1 are center of ball1, and x2,y2 are center of ball2
double distance = sqrt(dx*dx+dy*dy);
// Unit vector in the direction of the collision
double ax=dx/distance, ay=dy/distance;
// Projection of the velocities in these axes
double va1=(vx1*ax+vy1*ay), vb1=(-vx1*ay+vy1*ax);
double va2=(vx2*ax+vy2*ay), vb2=(-vx2*ay+vy2*ax);
// New velocities in these axes (after collision): ed<=1,  for elastic collision ed=1
double vaP1=va1 + (1+1)*(va2-va1)/(1+1);
double vaP2=va2 + (1+1)*(va1-va2)/(1+1);
// Undo the projections
vx1=vaP1*ax-vb1*ay;  vy1=vaP1*ay+vb1*ax;// new vx,vy for ball 1 after collision
vx2=vaP2*ax-vb2*ay;  vy2=vaP2*ay+vb2*ax;// new vx,vy for ball 2 after collision

ballspeedx =  vx1;
ballspeedy =  vy1;
balltwospeedx =  vx2;
balltwospeedy =  vx2;

ball.center = CGPointMake(ball.center.x + ballspeedx, ball.center.y + ballspeedy);
balltwo.center = CGPointMake(topbir.center.x + balltwospeedx, topbir.center.y + balltwospeedy);
or

double  x1=ball.center.x,  y1=ball.center.y,  x2=balltwo.center.x,  y2=balltwo.center.y,
vx1=ballspeedx,  vy1=ballspeedy,  vx2=balltwospeedx,  vy2=balltwospeedy;

double dx = x2-x1, dy = y2-y1;
// where x1,y1 are center of ball1, and x2,y2 are center of ball2
double distance = sqrt(dx*dx+dy*dy);
// Unit vector in the direction of the collision
double ax=dx/distance, ay=dy/distance;
// Projection of the velocities in these axes
double va1=(vx1*ax+vy1*ay), vb1=(-vx1*ay+vy1*ax);
double va2=(vx2*ax+vy2*ay), vb2=(-vx2*ay+vy2*ax);
// New velocities in these axes (after collision): ed<=1,  for elastic collision ed=1
double vaP1=va1 + (1+1)*(va2-va1)/(1+1);
double vaP2=va2 + (1+1)*(va1-va2)/(1+1);
// Undo the projections
vx1=vaP1*ax-vb1*ay;  vy1=vaP1*ay+vb1*ax;// new vx,vy for ball 1 after collision
vx2=vaP2*ax-vb2*ay;  vy2=vaP2*ay+vb2*ax;// new vx,vy for ball 2 after collision

ballspeedx =  vx1;
ballspeedy =  vy1;
balltwospeedx =  vx2;
balltwospeedy =  vx2;

dx=x2-x1, dy=y2-y1; d=sqrt(dx*dx+dy*dy);

double vp1= vx1 *dx/d+vy1*dy/d;
double vp2= vx2*dx+vy2*dy/d;
double dt =(r1+r2-d)/(vp1+vp2);

x1-= vx1*dt;
y1 -= vy1*dt;
x2-=vx2*dt;
y2-=vy2*dt;

ball.center = CGPointMake(x1, y1);
balltwo.center = CGPointMake(x2, y2);

x1+= vx1*dt;
y1+=vy1*dt;
x2+=vx2*dt;
y2+=vy2*dt;

ball.center = CGPointMake(x1, y1);
balltwo.center = CGPointMake(x2, y2);

ball.center = CGPointMake(ball.center.x + ballspeedx, ball.center.y + ballspeedy);
balltwo.center = CGPointMake(topbir.center.x + balltwospeedx, topbir.center.y + balltwospeedy);

the same in both programs. example:
ballspeedx=0;ballspeedy=4;balltwospeedx=0;balltwospeedy=-4;

3. After the collision the ball is stopped and disappear from the screen. vx1 ,vy1,vx2,vy2 values is -2145444...