# Circle collision detection and Vector math: HELP?

Hey so i'm currently going through the wildbunny blog to learn about collision detection, but i'm a bit confused on how the vectors he's talking about come into play

QUOTED BLOG:

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.

Ok so i understand that p is the distance each circle is penetrating each other, but i don't get what exactly N and P is. 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||) Whats 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.

-

I assume that A and B are the centers of the two spheres: Sa, Sb.

V = A - B is the vector that moves the center of Sa to the center of Sb: you see that A + V = B.

||A - B|| is the magnitude of V or modulus or length - as you prefere - that is the distance of the two spheres: p is how much the spheres are too close to each other.

N = V / ||A - B|| is a unit vector (length = 1) that shares the same direction of V so P = N·p si a vector that has the same direction of V and the length of p.

You don't want to move Sa toward Sb a little more so you will add P to B moving Sb far way from Sa in the right direction (N) and for the correct amount (p).

-