As a preliminary check, you can simply calculate the distance between a point and a line using a cross-product:
(x1,y1) = p1, (x2,y2) = p2 (cx, cy) = c = circle center delta = p2 - p1 (the difference vector) unit = delta/norm(delta) (the unit vector along the line segment) (c-p1) x unit = (cx-x1) * unity - (cy-y1) * unitx = d (distance of the circle center to the line)
Note that d has a direction (sign).
if d is outside the range [-R, R], then the line segment cannot cross the circle.
If the segments of your line do not move so much, you can save a unit vector for later reuse.
If the circle really intersects with the line (as opposed to the line segment), it still cannot intersect with the line segment. Check out these three conditions:
p1 lies inside the circle; norm (p1-c) Rp2 lies inside the circle; norm (p2-s) R- the closest point from the line to the center of the circle is between
p1 and p2 :
(unit . p1 < unit . c < unit . p2) or (unit . p2 < unit . c < unit . p1) where . is a vector point product.
If none of these conditions are met, they do not intersect.
You may also need to know where they intersect:
perp = (-unity, unitx) (The perpendicular vector) pclosest = perp * d + c (The point on the line closest to the circle center) dline = sqrt(R^2 - d^2) (The distance of the intersection points from pclosest) i{1,2} = ±dline * unit + pclosest
Obviously, you need to separately check whether i{1,2} between p1 and p2 , as in the third condition above.