Here is my first try to solve the polygon offset to other polygon. Actually, it can be easy modified to the offset line to other line.

Code: Select all

```
function get_offset (vertices, offset)
local offset_polygon = {}
print ( #vertices)
for i = 1, #vertices-1, 2 do
local x1, y1 = vertices[i], vertices[i+1]
local x2, y2 = vertices[i+2], vertices[i+3]
if not x2 then
x2, y2 = vertices[1], vertices[2]
end
local dx = x2-x1
local dy = y2-y1
local vnormx, vnormy = normalization (dx, dy, offset)
local nx = vnormy
local ny = -vnormx
if counter_clockwise or other_side then
nx = -vnormy
ny = vnormx
end
local px1, py1 = x1+nx, y1+ny
local px2, py2 = x2+nx, y2+ny
table.insert (offset_polygon, px1)
table.insert (offset_polygon, py1)
table.insert (offset_polygon, px2)
table.insert (offset_polygon, py2)
end
-- print ( #offset_polygon)
return offset_polygon
end
```