algorithm - circle-circle collision problem -


I have a problem finding circle-circle collision. I used the following algorithm

  function 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; Div = other.y-y; District = sqrt (sqr (dx) + sqr (dy)); If the & lt; = Radius + other.radius {// normalize dx / = dis; Div / district =; // Calculation of component of velocity in direction vp1 = hspeed * dx + vspeed * dy; Vp2 = other.hspeed * dx + other.vspeed * dv; If (vp1-vp2)! = 0 {dt = (radius + other. RDI-D) / (VP1-VP2); // Move the balls back so that they just touch X- = HSPID * DT; Y- = vspeed * dt; Other.x- = other.hspeed * dt; Other.y- = other.vspeed * dt; // Projection of 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 velocity in these axes vaP1 = (va1 + bounce * (va2-va1)) / (1+ mass / other.mass) keeping in mind the mass of each ball; VaP2 = (va2 + other.bounce * (va1-va2)) / (1 + other.mass / month); Hspeed = vaP1 * dx-VB1 * dv; Vspeed = vaP1 * DY + VB1 * dx; Other.hspeed = vaP2 * dx-VB2 * DY; Other.vspeed = vaP2 * DY + VB2 * dx; // We took the balls from time to time, so let us get them X + = HSPD * DT; Y + = vspeed * dt; Other.x + = other.hspeed * dt; Other.y + = other.vspeed * dt; }}} X = ball 1 x-rank y = ball 1 y-position other X = ball 2 x position other Y = ball 2 y position  

This algorithm works well when I have an image of a ball of 40 x 40 pixels and is the ball center (20,20) which means the image Only has a ball. But the problem occurs when the image size is 80 x 80. And the ball is the position of the center (60,60), it means the lower right corner of the ball radius 20. In this case, there are many collisions, that means the part

 x + = hspeed * Dt; Y + = vspeed * dt; Other.x + = other.hspeed * dt; Other.y + = other.vspeed * dt; Unable to isolate the ball / velocity does not vary according to the collision I have changed the value of X which adds the center of the figure 40,40 to 60,60 centimeters to 20. But the result is the same. Nobody can tell me what the problem is. I think the algorithm is right because it works in all other cases well and many people use this algorithm. The problem is changing from image center to ball center. What should I improve for this ??? Or any ideas Someone want me to help me give an email address to plz so that I can send my full project.   

I did not have the mental strength to digest your whole question, but to solve your problem here I have 2 cents

1) The easiest way to detect a cycle collision with another is to check if their distance is less than the radius of the combined circle (I can be mistaken with mathematics, so I Correct if i am wrong)

  circle c1, c2; Float distance = DISTANCE (c 1. center, c 2. center); If (distance & lt; c1.radius + c2.radius) {// collision .. BOOOOOOM}  

2) Try using exact data types Overflow, underflow and decimal digits Try changing the float to an integer without checking. Better still, just use Floats.

3) Write a log and trace it through your values. See if there are any clear math errors.

4) Break your code in its simplest part.

Try to remove all the velocity calculations to get the easiest movements to assist you.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -