I have a problem with circle-circle collision detection.I used the following algorithm
func collision(id,other.id) { var vaP1,vaP2,dis,va1,vb1,va2,vb2,vp1,vp2,dx,dy,dt; if (id!=other.id) { dx=other.x-x; dy=other.y-y; dis=sqrt(sqr(dx)+sqr(dy)); if dis<=radius+other.radius { //normalize dx/=dis; dy/=dis; //calculate the component of velocity in the direction vp1=hspeed*dx+vspeed*dy; vp2=other.hspeed*dx+other.vspeed*dy; if (vp1-vp2)!=0 { dt=(radius+other.radius-dis)/(vp1-vp2); //move the balls back so they just touch x-=hspeed*dt; y-=vspeed*dt; other.x-=other.hspeed*dt; other.y-=other.vspeed*dt; //projection of the velocities in these axes va1=(hspeed*dx+vspeed*dy); vb1=(vspeed*dx-hspeed*dy); va2=(other.hspeed*dx+other.vspeed*dy); vb2=(other.vspeed*dx-other.hspeed*dy); //new velocities in these axes. take into account the mass of each ball. vaP1=(va1+bounce*(va2-va1))/(1+mass/other.mass); vaP2=(va2+other.bounce*(va1-va2))/(1+other.mass/mass); hspeed=vaP1*dx-vb1*dy; vspeed=vaP1*dy+vb1*dx; other.hspeed=vaP2*dx-vb2*dy; other.vspeed=vaP2*dy+vb2*dx; //we moved the balls back in time, so we need to move them forward x+=hspeed*dt; y+=vspeed*dt; other.x+=other.hspeed*dt; other.y+=other.vspeed*dt; } } } x=ball 1 x-position y=ball 1 y-position other.x= ball 2 x position other.y=ball 2 y position this algorithm works well when i have a ball image of 40 x 40 pixel and ball center is (20,20) means image consists only ball.But the problem arises when image size is 80 x 80.and ball center position is (60,60),means ball is lower right corner with radius 20. in this case there are multiple collision occur,means the portion
x+=hspeed*dt; y+=vspeed*dt; other.x+=other.hspeed*dt; other.y+=other.vspeed*dt;
unable to seperate the ball /velocity does not change according to collision. I have changed the value of x which is the center of image 40,40 to 60,60 center of ball adding 20.but the result is same .Can any one tell me what is the problem.I think algorithm is correct because it works nicely in all other case and lots of people used this algorithm.problem is changing position from image center to ball center.what correction should i do for this??? or any idea.if someone want to help plz give me e-mail address so that i can send my full project.