In the context of a game program, I have a moving circle and a fixed line segment. The segment can have an arbitrary size and orientation.
I am having difficulties trying to compute:
Mathematical Idea. . If that distance is less than or equal to the circle's radius, then a part of the line lies inside the circle or touches it, and therefore, the line collides with the circle.
To determine the position of a line with respect to a circle, all we need to do is find its distance from the center of the circle, and compare it with its radius. Then, if the distance is less than the radius, the line must intersect the circle at two distinct points.
I'm going to answer with pseudo-algorithm - without any code. The way I see it there are two cases in which we might return true, as per the image below:
Here in blue are your circles, the dashed line is the trajectory line and the red line is your given line.
From the trajectory we build normal lines to each point A and B. Then these lines are chopped or extended into helper lines (Ha
and Hb
), so that their length from A
and B
is exactly the radius of the circle. Then we check if each of these helper lines intersects with the trajectory line. If they do return true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With