Jump to content
  • Advertisement
Sign in to follow this  
reaperrar

Circle-Circle collision intersection point

This topic is 2558 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Given two circles, each with an old position (where they are not colliding) and a new position (where they are colliding)... How can I find at what point they collide between the old and new position?

Share this post


Link to post
Share on other sites
Advertisement
Wouldn't they technically collide at a minimum of two points?

Edit: re-read it. Perhaps you mean at what time ??

Share this post


Link to post
Share on other sites
yes, at what point in time does the distance between the two circles, minus the radius of both circles... equal zero

Share this post


Link to post
Share on other sites
Hmm. I'm trying to think of a way to do this and I'll try to do some math on paper but I have a sort of quick way you could figure it out.
Find the two points the circles collide at.
Reverse the velocities of the circles.
Increment the positions of the circles with the negative velocities at a set amount of time.
When the two points of intersection are roughly the same point calculate the number of time steps to get to this point.

So you have the point in time from the current time the two circles first intersected.

Share this post


Link to post
Share on other sites
I attempted to write it out algebraically... not sure if this is right:
D - distance between circles
T - time
C1/C2 - circle1/circle2

D =
Sqrt(
(C1.XOLD + T * (C1.XNEW - C1.XOLD) - (C2.XOLD + T * (C2.XNEW - C2.XOLD)))^2 +
(C1.YOLD + T * (C1.YNEW - C1.YOLD) - (C2.YOLD + T * (C2.YNEW - C2.YOLD)))^2
) - C1Radius - C2Radius

If that is correct, I'd probably have trouble rearranging it to make T the subject : /

Share this post


Link to post
Share on other sites
let x1/2 be circle positions, r1/2 radii, v1/2 velocities

||x1+t.v1 - x2-t.v2||=r1+r2
||(x1-x2) + t(v1-v2)||=r1+r2
||x1-x2||^2 + t^2||v1-v2||^2 + 2t(x1-x2).(v1-v2) = (r1+r2)^2

and done. quadratic equation in t. solve for both values; choose minimum t value >= 0

Share this post


Link to post
Share on other sites
It's a quadratic equation, whos solutions have been known for over a thousand years and is taught in high school ;)

at^2 + bt + c = 0 -> t = (-b +/- sqrt(b^2 - 4ac)) / 2a

here, a = ||v1-v2||^2, b = 2(x1-x2).(v1-v2), c = ||x1-x2||^2 - (r1+r2)^2

Share this post


Link to post
Share on other sites
Ok I'll attempt to implement that, though I'd like to clarify...

Anything between || || is to be normalized, and the " 2(x1-x2).(v1-v2)" part is the (dot product between the two resulting vectors) * 2?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!