# Circle-Circle collision resolution

This seems easy but I can't figure it out, when I have one circle(c1) collide with another(c2) I give the c2 circle the heading of c1 and send the c1 circle on the normal vector to the heading (the heading is stored as vector = (cos(theta), sin(theta)) this is probably a bad solution). So this works great when c1 is colliding head-on with c2, however if c1 collides with it's tail into c2 then c2 takes the direction that c1 is facing which causes them to intersect each other. Any ideas of how I can "re-word" the heading vector so it's not dependent on theta (the angle that c1 is looking at in the cartesian plane)?

Here is an example: Elastic Collision

• I don't know why you are using any angles for circular collision it's just if(distance between the two centers of each circle < radius of circle 1 + radius of circle 2) Apr 13, 2015 at 2:32
• I'm having issues with resolving the collision in a somewhat realistic manner not the collision itself. Apr 13, 2015 at 4:31

The question sounds like it is describing a problem with object penetration. (When one circle is overlapping the other and it causes the deflection to be calculated wrong).

This is a problem with the precision of the collision tests. If I have understood the problem correctly, what is happening is that collision detection only happens once per frame but the object is moving too fast in a single frame. The collision with the correct edge is missed. When the collision test occurs, the object has already passed through and is then deflected off the other side.

The key thing to fix this is to limit the speed of your moving objects to less than half their width. This would ensure that your collision is always detected on the correct side. This will still allow objects to penetrate though and anytime you have object penetration your physics will be inaccurate, though it's often good enough.

You can improve on this by offsetting the penetrating objects so that they are just touching (IE. rewind to the point where they actually collided), then perform your deflection calculations based on the corrected positions.

If you want accurate results or need fast moving objects (good for billiards and similar high speed collisions), then you need to implement sweeping collision detection. Basically, instead of checking once per frame, you check X times per frame, depending on how much precision you want.

Your solution is correct, but only for a very specific type of collision. Even the gif is really only valid if a moving circle hits a stationary circle - not if two circles are moving and hit each other. Since you probably want to be able to make this work regardless of how the circles are moving when they collide, you'll need to do some calculations.

Short description: find the normal vector between the two touching circles, and know that each circle will have its velocity vector essentially flipped over that line - that gives you the direction of the resultant velocities. Use conservation of momentum to find their magnitudes. For the actual math I found http://www.hoomanr.com/Demos/Elastic2/ seems to explain it reasonably.

• My current solution, using trig for headings, is something I came up on my own so I wasn't sure if it was completely off for this purpose. And yes, I am trying to simulate an elastic collision like this: en.wikipedia.org/wiki/Momentum#/media/… Apr 13, 2015 at 4:35
• Remark: answers that are not answers, but dialog, should be comments. Alternatively, use the chat for detailed, more private discussions. When people read the "answers" section, they expect something a bit different. Apr 13, 2015 at 4:54
• @R1v2 updated my answer Apr 13, 2015 at 6:02
• do u have a code example? Jul 5, 2022 at 13:21