Polygon Clipping

The question I have here is quite hard for me to describe in words… So I’ll use Pictures!
In general, The issue I have is as follows:

Say I have Polygon A:

  • WebGL Multiple Canvas three.js example
  • Internet Explorer 10 canvas clipping unexpected behavior
  • HTML5 Canvas not clipping correctly?
  • Canvas - Fill a rectangle in all areas that are fully transparent
  • Can you have multiple clipping regions in an HTML Canvas?
  • html5 canvas - merge two clipping regions - James Bond Gunbarrel
  • Polygon A

    Which is intersected at two points by an open polygon B:

    Polygon B Intersecting A

    What algorithm can I form two closed polygons out of this intersection? (Note that there are three solutions here the one I’m searching for is highlighted)

    enter image description here

    The preferable solution is

    • The Smallest of all solutions given that:
    • A does not contain B

    So, any suggestions on how to generate B (and a new A) after the intersection takes place? I’m new to Polygon Math (and 2D Shape interaction in general) so I have no idea where to start or where to look!

    Thanks!

  • WebGL Multiple Canvas three.js example
  • HTML5 Canvas not clipping correctly?
  • Internet Explorer 10 canvas clipping unexpected behavior
  • Canvas - Fill a rectangle in all areas that are fully transparent
  • Can you have multiple clipping regions in an HTML Canvas?
  • html5 canvas - merge two clipping regions - James Bond Gunbarrel