Reputation: 5074
If you were given a set of pairs of lines, how would you find the amount of area which is contained by all pairs of lines (if it exists)? For example, if I had the pairs of lines:
((0, 0), (0, 10)) & ((10, 0), (10, 10))
and
((0, 0), (10, 0)) & ((0, 10), (10, 10))
how would you go about finding the area enclosed by all those lines (which in this simple case would be a square defined by points (0,0),(10,0),(10,10) & (0,10).
What algorithms might point me in the direction of solving such a problem?
EDIT: The lines won't always touch at the ends or intersect with each other. If there exists a pair of lines which doesn't intersect any of the other lines and doesn't touch at the edges, then it can be concluded that that set of pairs of lines does not have an area enclosed by all of them.
EDIT2:Take the following sets of lines:
pair 1: ((0, 0), (10, 0)) & ((0, 10), (10, 10))
pair 2: ((0, 0), (0, 10)) & ((10, 0), (10, 10))
pair 3: ((2, 0), (2, 10)) & ((8, 0),(8, 10))
The enclosed area by those three pairs of lines is the area defined by points (2,0),(2,10),(8,10) and (8,0). The convex hull algorithm however would return the values (0,0),(10,0),(10,10) and (0,10).
Upvotes: 1
Views: 341
Reputation: 8641
EDIT: it appears the convex hull is not the solution.
Just to make sure I understand your problem: is that the red area in this picture that you want?
Upvotes: 1
Reputation: 6246
Find all points of intersection which stay within the line segment for all pairs of lines. If no of points are less than 4 then no enclosed shape found.
If 4 points found then clip the lines with those points.Use flood fill to get the area of figure enclosed in the points.
Upvotes: 0