I have polygon chains similar to the following...

...given the chain in the image, how would I go about calculating a chain that defines *the same shape* but *without* crossing paths?

Specifically, in the case of the image, the result I want looks like this:

A1,

A2,

Intersect between A2 and A3,

Intersect between A3 and A4,

A4,

A5,

Intersect between A3 and A4,

A3,

Intersect between A3 and A2,

A6

I'm looking for an algorithm to accomplish this for any chain, but I'm not sure what I'm trying to do is even called, which makes searching for a solution tricky.

If there's a name for what I'm trying to do it would be of great help to know it.

Thank you for any assistance!