Consider the picture :
Given the black "irregular line" segments, I want to have the green boundary surrounding them.
My Attempt to solve :
Note, that I need to capture the concavity. Thus the convex hull algorithm will not work. I have used some interpolations, to draw the straight line segments indicated by overlayed red stripes. Then I attempted to run a sweep algorithm. These stripes are roughly parallel, if that helps.
That is, their headings lay within some small interval.
Heading H in { angle alpha - x , angle alpha +x } union { angle alpha - x + 180 , angle alpha +x+ 180 } for some small x
However, it needs to be guaranteed, that the green boundary should not intersect any red lines.
So, my naive attempt was :
- Start at leftmost vertex of all lines.
- Pick the line attached to the vertices. (if more vertices, then take the top most and bottom most)
- Use this line to "partition" the plane. (or two lines or two "separatices", if 2 vertices)
- Pick the next leftmost unvisited vertices.
- See if the vertex lies above the top separatrix or below the bottom separatrix.
- If above the top separatrix, add it to a set called "top chain", if below the bottom one, the add to bottom chain.
But this runs into problems.
The problem
To determine whether the newly picked point is at the top or at the bottom of a separatrix, I use the vector product method. But consider this :
Imagine you are at the green square. Your separatrix now is the black line, vector pointing to the left, as the arrow shows.
At this stage, you compare this with the green vector showing the next vertex to be picked on the blue line. The vector method, intended to measure angles between -Pi to Pi will consider this a negative value. Thus the point, although necessary, will not be picked up.
If you reverse the direction of the vector, then the Magenta line will not be picked up.
Question
How to efficiently solve this problem? I am using D, so bonus if there is a D library capable of this.