How does this circle collision detection math work?

Posted by Griffin on Game Development See other posts from Game Development or by Griffin
Published on 2011-06-27T09:02:38Z Indexed on 2014/06/04 15:47 UTC
Read the original article Hit count: 240

I'm going through the wildbunny blog to learn about collision detection. I'm confused about how the vectors he's talking about come into play.

Here's the part that confuses me:

p = ||A-B|| – (r1+r2)

The two spheres are penetrating by distance p. We would also like the penetration vector so that we can correct the penetration once we discover it. This is the vector that moves both circles to the point where they just touch, correcting the penetration. Importantly it is not only just a vector that does this, it is the only vector which corrects the penetration by moving the minimum amount. This is important because we only want to correct the error, not introduce more by moving too much when we correct, or too little.

N = (A-B) / ||A-B||

P = N*p

Here we have calculated the normalised vector N between the two centres and the penetration vector P by multiplying our unit direction by the penetration distance.

I understand that p is the distance by which the circles penetrate, but I don't get what exactly N and P are. It seems to me N is just the coordinates of the 3rd point of the right trianlge formed by point A and B (A-B) then being divided by the hypotenuse of that triangle or distance between A and B (||A-B||). What's the significance of this?

Also, what is the penetration vector used for? It seems to me like a movement that one of the circles would perform to get un-penetrated.

© Game Development or respective owner

Related posts about collision-detection

Related posts about vector