How can I detect whether a circle intersects or crosses a given arc segment?
The arc is defined by a center, radius, start angle (angle1), and end angle (angle2). How to detect that arc AB has intersection with the circle D?
I see that the first step is to check if the distance between points C and D is less than the sum of their radii.
But how do I check if the circle touches only the arc part, not the whole circle?
Now my solution doesn't work well:
The name of the problem: circular obstacle pathfinding
Thanks all for the comments!
It's really easier than I think:
-- check if an arc intersects a circle
local function isArcCircleIntersection(arc, circle, rightDir)
-- arc.x, arc.y, arc.radius is a first circle
local intersectionPoints = findCircleIntersections(arc, circle) -- returns array of collision points
for _, point in ipairs(intersectionPoints) do
local angle = math.atan2(point.y - arc.y, point.x - arc.x)
local da1 = normalizeAngle(angle - arc.angle1) -- above
local da2 = normalizeAngle(arc.angle2 - angle) -- below
if rightDir then -- the other direction
da1, da2 = da2, da1
end
if da1 >= 0 and da2 >= 0 then
return true -- the given angle was between of two angles
end
end
return false
end
So the arc will be recognized correctly!