Jump to content
  • Advertisement
Sign in to follow this  
__fold

Intersection test between two moving circles

This topic is 4790 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

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 this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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)



Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

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!