I'm trying to do a mesh-to-circle collision system for my game. I've seen some examples where you iterate over all the verts of the mesh and check if they are inside the circle. But the problem is that sometimes the vertices are not inside the circle, but the lines that this vertices form are. In this cases, the collision check evaluates to false when it should evaluate to true. How can I make a good collision detection of this type? (in c/c++)
Asked
Active
Viewed 863 times
3 Answers
3
If you want you could calculate the distance from the line to the center of the circle. But I think it will be too costly. If the distance is lower than the radio you could have a collision. You will need to check if this part of the line is between the points. Distance line to point

rbelli
- 393
- 1
- 6
-
But I need to use a concrete point for the distance check, because it may collide in the middle of the line, but not at the end. How do I know what point of the line I have to use? – XaitormanX Mar 27 '12 at 20:58
-
1The maths will give you the shortest distance between a point (the center of your circle) and a line (each vertex of your mesh). You can also read http://www.intmath.com/plane-analytic-geometry/perpendicular-distance-point-line.php, http://tog.acm.org/resources/GraphicsGems/index.html, http://forums.codeguru.com/showthread.php?t=194400 and http://www.merl.com/projects/vclip/ – j4x Mar 28 '12 at 11:23
2
Actually, a quick google lets you know that this is a duplicate of a question already on stack overflow: Circle line-segment collision detection algorithm?
1
Just iterate over all the edges. And don't worry about the vertices: if a vertex is inside the circle, some edge is bound to cross it (unless the entire grid is inside the circle, which I'm guessing isn't likely).

Beta
- 96,650
- 16
- 149
- 150
-
And how do I iterate over an edge? I can just know the position of a concrete point, but not of an edge, can I? – XaitormanX Mar 27 '12 at 20:54
-
So your question is how to determine whether the straight line segment between two given points crosses a given circle? – Beta Mar 27 '12 at 21:09
-