Advertisement

Line-Segment - Circle Intersections

Started by July 01, 2003 01:07 PM
3 comments, last by Endemoniada 21 years, 7 months ago
Hi, I''ve been doing line-segment - line-segment and line-segment - circle intersections for collision detection of circles against straight walls and all seemed well. Now I ran in to a problem. If the circle hits an outer corner (like this _| with the circle going up and left) the line segment penetrates the circle but doesn''t come out the other side, and multiple segments can do that at any given time. What should I do ? I can determine if the endpoints lie in the circle but that involves a sqrt() and I''m not sure what to do with that information anyway. Also, does anyone know if there are any articles on pinball-like or pool-like collision detection ? I can''t find much. The articles I found deal mostly with the reaction after the collision. Thank you.
That''s pretty easy: check if the corner is inside your circle. It doesn''t require a sqrt; you can compare the squared distance against the squared radius. If it is inside, it is the collision point. You can treat it as a wall passing through the corner, parallel to the sphere''s surface at that point.

Cédric
Advertisement
And don''t worry about square roots; Premature optimization is the root of all evil.
if you want a single impulse at that point (because the circle is gonna hit two walls), store your segments as indices to points, and store the index of the point when the ball hits the horizontal wall. When you collide with the vertical wall, check if corner is already in the list of collided points. If so, don't add it to the list.

This kind of collision detection is always a bit dodgy, as you'll get spurious collision points, which generate unwanted impulses (like the ball colliding with an almost flat corner, hitting a corner and a neighbouring wall).

Dynamic collision detection (with a moving sphere) is much better, but the calculations are a little bit more complicated. Also, you still have to deal with cases like in the static collision tests, when the speed of the ball is close to 0. Without using the velocity (and possibly acceleration) of the particle, you can miss collisions, especially with a fast moving ball, like in a pinball machine.

there are several ways to do dynamic collsion detection with static environments, BSP trees, quad trees, ... BSP trees have the advantage of doing reducing the collision tests to plane tests. Look for Stan Melax's Dynamic plane shifting collision paper.

[edited by - oliii on July 1, 2003 3:44:55 PM]

Everything is better with Metal.

Thanks guys,

I''m a newbie when it comes to this stuff but I''m learning. I''m doing everything in 2D now until I fully understand what is going on. I''m trying to make a game similar to pool.

I think I''m using dynamic collision detection because, for every frame, I calculate the next ball position (based on it''s velocity), this way if it goes really fast and skips over a wall I can tell. Is that what dynamic collision detection means ?

I will work with what you guys gave me now and see if I can learn more. I hope I can find that paper you gave me oliii.

Also, I learned how to avoid the square root in a gamasutra article :o) It''s about balls hitting each other but not walls :o(

I''ll be back...


This topic is closed to new replies.

Advertisement