Circle rounding circle

I struggle to find a solid solution to detect collisions between a circle and a segment of a circle. Imagine a field of view cone for an enemy playing with circles representing objects of interest.

The diagram below is what I drew to try to work out some possible cases, but I'm sure there are more.

I understand how to quickly eliminate extreme cases, I discard any goals that don’t collide with the whole circle, and any cases where the center of the main circle is within the target circle are automatically correct (E in the diagram).

I'm struggling to find a good way to check out the rest of the cases. I tried to compare the distances between the centers of the circle and the end points of the outer lines of the segments, and I tried to work out the angle of the center of the target circle from the center of the main circle and determine if it is inside the segment, but none of the methods are suitable for all cases.

In particular, it seems that he is scared if the target circle is close to the center but does not touch it (somewhere between E and B below) or the segment is narrower than the target circle (so that the center is inside the segment but both edges are outside it )

Is there a reliable way to do this?

Additional information: The segment is described by the position P, the orientation O (the value of which is the radius of the circle) and the size of the representation S.

My most successful attempt to spend time is to determine the angles of the vectors ca1 and ca2 and to check whether one of them lies between the angles of the vectors a1 and a2. This works in some cases, as described above, but not in situations where the target circle is larger than the segment.

Edit 2 After implementing the best offer from below, there is still a false positive that I am not sure how best to eliminate. See the pink chart below. The circle in the lower right column indicates that it collides with the segment because it limits the overlap of both half spaces and the main circle.

collision typescurrent solution

false positiveedge case


Final editing

After discovering another edge case (4th image), I settled on an approach that combines the top two answers from the bottom and seems to cover all the bases. I will describe it here for those who follow.

First, exclude anything that does not give a quick test with circle to circle.

Then check for a collision between the circle and the two outer lines of the segment. If it is, return true.

Finally, perform a pair of point-to-half-space tests using the center of the circle and two outer lines (as described by Gareth below). If it passes both of them, otherwise returns false.

+7
algorithm collision-detection trigonometry circle game-physics
source share
3 answers

but. Check if she intersects with a whole cirlce.
B. Check if it intersects with straight lines.
C. If not, check if the angle between the centers of the circle is in the range of the angular segment (the dot product is suitable for this).

Crossing requires A && (B || C)

+3
source share

The round segment (with a central angle of less than 180 °) is the intersection of three figures: a circle and two half-planes:

alt text

Thus, a shape crosses a circular segment only if it crosses all three of these shapes. [This is only if, but not if; see below.]

Intersecting a circle / circle is easy (compare the distance between their centers with the sum of their radii).

For the circle / half-plane intersection, we represent the half-plane in the form p · n ≤ k (where p is the test point, n is the unit vector normal to the line defining the half-plane, and k is a constant). Then a circle with center x and radius r intersects the half-plane if x · n ≤ k + r.

(If you need to process a round segment with a central angle of more than 180 °, divide it into two segments with a central angle of less than 180 °. If I understand your description of the problem correctly, you will not need to do this, since your field of view will always be less than 180 °, but worth mentioning.)

Edited to add: as indicated in beeglebug, a circle can intersect all three shapes without intersecting their intersection. Unfortunately. But I believe that this can only happen when the circle is outside the center of the segment, as shown in the diagram below, in which case we can apply the dividing axis test for convex shapes.

A circle failing to intersect a circular segment, with an axis shown separating them

The dividing axis theorem says that two convex figures cannot intersect if there is a line such that one figure lies completely on one side of the line and the other on the other.

If in this case there is any dividing axis, then the axis perpendicular to the line between the center of the circle and the center of the segment is the dividing axis (as shown).

Let the center of the segment be at the origin, let the circle have the center x and radius r, and the two half-planes have (external) normals n₁ and n₂ . The circle is “behind” the segment if

x . n₁ > 0 and x . n₂ > 0

and the axis separates it from the segment if

| x | > r

A circle failing to intersect a circular segment, with an axis shown separating them, with points, normals and radius marked

+3
source share

Mmmm, why not: 1) exclude all circles that do not intersect the square EE '(the logical point has a square); 2) with those that intersect the square, check the radius of the main area (field) with the distance between these circles to the center of the area.

Fast, but only works with 90 degree segments (as in the first picture).

0
source share

All Articles