Search code examples
c#algorithmgeometrycomputational-geometry

Finding the specific outline of a set of points


I have a set of "blocks" (denoted by the red and green lines) that are placed inside a "container" (denoted by the blue lines).

enter image description here

All of the intersection points of the blocks (green and red dots) and all relevant information of the container (angle, gradient, start,end points, etc.) are known.

I want to extract the "top-most" outline of the resultant figure after the blocks are placed (denoted by the green lines and dots).

I tried to use methods such as convex hull (shown by purple lines in the following diagram), but it does not give the exact lines.

enter image description here

My question is can anyone point me to a solution or some kind of algorithm that I can apply to solve these type of problems?


Solution

  • Fill the list (array ) with all points. (Repeat points in T-nodes like 2nd green point at your picture)
    Sort this list by Y-coordinates
    Scan list (starting from top points) like sweep line algorithm.
    At every stage you'll get a pack of points with the same Y-coordinate (a pair or more).
    Remove points covered be intervals (see below) both from left and from right.
    Make intervals (by X-coordinates) from pairs of these points.
    Add these intervals in interval (segment) tree.
    Join neighbor intervals.
    Repeat until single interval cover all the top part.