Unfortunately, I do not have enough reputation for comments, so I am adding this as another answer instead ...
Cristiano is great for checking that a circle overlaps one of the segments of a polygon line, but he does not verify that the more unusual case is when the circle is completely inside the polygon, which can happen if a small fast moving circle collides with a large polygon.
I tried the code below for Cristiano with a little modification to fix the problem ...
public static boolean overlaps(Polygon polygon, Circle circle) { float []vertices=polygon.getTransformedVertices(); Vector2 center=new Vector2(circle.x, circle.y); float squareRadius=circle.radius*circle.radius; for (int i=0;i<vertices.length;i+=2){ if (i==0){ if (Intersector.intersectSegmentCircle(new Vector2(vertices[vertices.length - 2], vertices[vertices.length - 1]), new Vector2(vertices[i], vertices[i + 1]), center, squareRadius)) return true; } else { if (Intersector.intersectSegmentCircle(new Vector2(vertices[i-2], vertices[i-1]), new Vector2(vertices[i], vertices[i+1]), center, squareRadius)) return true; } } return polygon.contains(circle.x, circle.y); }
Phil anderson
source share