Assume that the polygon is specified by vertices v1, v2, ..., vn.
v0 = vn
s = v0;
for j = 1 to n do
p = vj mod n
if p is "inside" then
if s is "outside" then
output intersection of line sp with edge
endif
output p
else
if s is "inside" then
output intersection of line sp with edge
endif
endif
s = p
endfor