# Circle-Circle collision intersection point

## Recommended Posts

reaperrar    136
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 on other sites
KanonBaum    277
Wouldn't they technically collide at a minimum of [b]two[/b] points?

Edit: re-read it. Perhaps you mean at what [i]time[/i] ??

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

##### Share on other sites
bloodisblue    137
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 on other sites
reaperrar    136
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

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

##### 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 on other sites
reaperrar    136
Sorry I don't understand... how can I find out what time they collide if t isn't the subject?

##### 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 on other sites
reaperrar    136
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 on other sites
normalized, what no. ||x|| means the length of x

reaperrar    136
Kk ty

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account