- Step one: find all intersection
points, in any order. For polygon,
you need to find intersection of red
line and line of each segment. Just solve system of two linear equations. If solution is constrained to polygon segment limits, you
have an intersection.
- Step two: sort found points by
position on red line. You know that first and last point are outer ones. "Outerness" flips with each point - outer-inner-outer and so on. Between two adjacent outer points you have inner line segment (green). Edit: not true... Start with point #0, segment #0 - #1 is inner, next is outer, next is inner again and so on.
If region is not polygon, but is given by some implicit function, you need to find where that function is equal to red line (approach depends on function, of course).