Line Offset Algorithm

Hello,

I need to find out how works good polyline offset. Like Offset tool in Autocad. ‘good’ means no knots, no inversed lines and other bad stuff.

Links, advices?

Like this: