Polynom in Polynom version:
Lua Code:
local triangle = {
[1] = {x = 0, y = 0},
[2] = {x = 1, y = 0},
[3] = {x = 0, y = 1}
}
local square = {
[1] = {x = -1, y = 0},
[2] = {x = -2, y = 0},
[3] = {x = -1, y = 1},
[4] = {x = -2, y = 1}
}
local function PolynomInPolynom(p1, p2)
local c = { }
for i = 1, #p2 do
c[i] = false
for j = 1, #p1 do
local k = j + 1
if k > #p1 then
k = 1
end
if ((p1[j].y > p2[i].y) ~= (p1[k].y > p2[i].y)) and (p2[i].x < (p1[k].x - p1[j].x) * (p2[i].y - p1[j].y) / (p1[k].y - p1[j].y) + p1[j].x) then
c[i] = not c[i]
end
end
if c[i] then
return true
end
end
return false
end
print(PolynomInPolynom(triangle, square)) -- false
It's not perfect, but it's pretty accurate.