Intersection test between two moving circles

Started by
28 comments, last by Eelco 18 years, 10 months ago
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.
Advertisement
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
We have youth, how about a fountain of smart.e4 e5 f4 d5
Tang of the Mountain: It's just pseudo-code so ^ equals pow.
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...
We have youth, how about a fountain of smart.e4 e5 f4 d5
Quote:Original post by __fold
Now I want to know if there is a t that satisfies this statement:

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



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.
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.
edit totally wrong i didnt see the t in sin

[Edited by - Raymond_Porter420 on June 1, 2005 8:32:42 PM]
Quote:Original post by Eelco
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


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 Eelco
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.


That is a really good idea!

Quote:Original post by Eelco
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.


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

Thanks alot!
Quote:Original post by moagstar
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.


Hmm, I have to think about this. I'm not sure I understand what you mean.

This topic is closed to new replies.

Advertisement