I need a way to check if two arcs occupy the same space in a given circle, but I am unsure of how to go about it. The idea is that I can create nodes off of other nodes in my game, with each node having a specific arc / cirlce segment size. Of course, these segments must not occupy the same space in the given node.
Example of desired outcome:
What I have so far, which works in some cases :
Code: Select all
function pie:addSegment(start, size, r, g, b)
local fits = true
for _, segment in pairs(self.segments) do
if (start + size > segment.start
and start + size < segment.start + segment.size) then
fits = false
break
end
end
if not fits then
print("That segment can not fits!1!!")
else
table.insert(self.segments, { start = start, size = size, r = r, g = g, b = b })
end
end
micha wrote:...
If this still does not work (rounding errors, maybe) then you can introduce an angular tolerance, which is a maximum overlap that is allowed:Code: Select all
function arccollision (mid1, width1, mid2, width2) delta = math.abs( (mid1-mid2+math.pi)%(2*math.pi)-math.pi) if delta <= (width1+width2)/2 - tolerance then return true -- collision end return false end