# Intersection test between two moving circles

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

## Recommended Posts

I want to do an intersection test between two moving circles. Not too hard but, one of them is moving in a circular motion. :) Other solutions are welcomed! This picture might clearify it a bit. (A is actually at the origin of the big circle but the constants are not that important.) # == plus sign So i have this: The two moving objects. C1 = A # Bt C2 = C # Dt r1 and r2 is the radius for the moving circles. Where: A = (A.x, A.y) Bt = (r * cos(a # bt), r * sin(a # bt)) (r is the distance from the center of the big circle to the circumference) C = (C.x, C.y) Dt = (D.x * t, D.y * t) deltaX = (C.x # D.x * t) - (A.x # r * cos(a # bt)) deltaY = (C.y # D.y * t) - (A.y # r * sin(a # bt)) Now I want to know if there is a t that satisfies this statement: sqrt(deltaX ^ 2 # deltaY ^ 2) == (r1 # r2) (the distance between the centers of the circles is equal to the sum of the radius and the objects are touching eachother) I've tried to solved this thing but I can't seem to get it right. Just by the definition of the problem, I can see that there should be a really simple solution to this problem. The problem should have at least two t values that are correct if a solution exists. I'm only interested in the first positive solution.

##### Share on other sites
wll...ive seen this problem before....youre algorithm is correct...is the distance between the two centerpoints less than or equal to the sum of the radii, however

sqrt(deltaX ^ 2 # deltaY ^ 2) == (r1 # r2)

is wrong...the ^ operator is an Exclusive or not a power operator

try:
sqrt(pow(deltaX,2) # pow(deltaY,2))

or

sqrt( deltaX * deltaX # deltaY * deltaY)

hope this helps

##### Share on other sites
Tang of the Mountain: It's just pseudo-code so ^ equals pow.

##### Share on other sites
you should probably state that...being as the operator you used....exists as another function altogether....the code works as I and you have stated...so I dont know what you are looking for...

##### Share on other sites
Quote:
 Original post by __foldNow I want to know if there is a t that satisfies this statement:sqrt(deltaX ^ 2 # deltaY ^ 2) == (r1 # r2)

##### Share on other sites
you should realize that the distancefunction between the two circles is a periodic function, and there are potentially infinite solutions to the problem distance=0

one way to get a good approximation is to sample the distance function at a couple of points: say 3. at the start of your timeinterval, the middle and the end, then fit a quadratic polynnmal through it, and solve for its roots.

ideally you should check for the accuracy obtained and further refine the solution if so desired, although for sane rotationspeeds, one iteration will most likely be enough.

##### Share on other sites
Couldn't you take the instantaneous tangent velocity and use that in a ray-sphere intersection test (increasing one of the sphere's radius by the others, using the other sphere centre for the ray origin and the velocity vector for the ray direction) Just a thought.

##### Share on other sites
edit totally wrong i didnt see the t in sin

[Edited by - Raymond_Porter420 on June 1, 2005 8:32:42 PM]

##### Share on other sites
Quote:
 Original post by Eelcoyou should realize that the distancefunction between the two circles is a periodic function, and there are potentially infinite solutions to the problem distance=0

Yes, I understand that but I hoped that there was a way to obtain the "first" positive solution or a solution where t is in a specified range, (0, 1] for instance.

Quote:
 Original post by Eelcoone way to get a good approximation is to sample the distance function at a couple of points: say 3. at the start of your timeinterval, the middle and the end, then fit a quadratic polynnmal through it, and solve for its roots.

That is a really good idea!

Quote:
 Original post by Eelcoideally you should check for the accuracy obtained and further refine the solution if so desired, although for sane rotationspeeds, one iteration will most likely be enough.

For my purpose, I don't think I have to refine it.

Thanks alot!

##### Share on other sites
Quote:
 Original post by moagstarCouldn't you take the instantaneous tangent velocity and use that in a ray-sphere intersection test (increasing one of the sphere's radius by the others, using the other sphere centre for the ray origin and the velocity vector for the ray direction) Just a thought.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 95
• 11
• ### Forum Statistics

• Total Topics
632973
• Total Posts
3009636
• ### Who's Online (See full list)

There are no registered users currently online

×