# Converting lines to polygons

I have a set of 2D lines that make up one or more polygons (which can share sides). Can anyone describe an algorithm that will give me the polygon vertices?
LVL 1
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Coplanar lines are either coincident, parallel, or they intersect at a point. Assume you have the slope-intercept form of the line: the lines are coincident if the slope and intercept are the same. They are parallel if the slope is the same and they are not coincident. They intersect if they are neither of the above and the point of intersection is the point that satisfies the two simultaneous equations

y = m*x + b
y = n*x + c

where m,n are slopes and b,c are intercepts.

The union of the pair-wise intersection points of the lines is the collection of all of the vertices of all of the polygons formed by the lines.

Hope this helps, -bcl
0
Commented:
How is your set of 2D lines represented?
0
Author Commented:
Each line is represented by it's two end points - a pair of (x, y) co-ordinates.

I'm nearly there I think. Each point (that potentially comprises a polygon) has two or more lines associated with it. Basically I navigate around each point always turning left (taking the line with the smallest relative angle). Once I reach the start point I output a polygon comprisied of each point visited. I only allow one journey down each line (in both directions) for dealing with polygons that overlap.
0
Commented:
That could work.   Do any of the lines intersect other than at their end points?  Can polygons that "overlap" share more than their borders?
0
Author Commented:
Yes, two polygons can share one or more sides.
0
Commented:
Sharing sides should pose no problem.  I was wondering if they could share area.
0
Author Commented:
Yes they can. I don't think this poses a problem either, but I'd be interested in your train of thought.
0
Commented:
Actually I was wondering if you'd need to trace vertices of your polygons not in your list of endpoints but formed by the intersection of two of your line segments.
0
Commented:
Points (250) refunded and question closed.

Netminder