Computing polygons from intersecting lines

I have a bounding rectangle that a user can add lines onto. The lines will always extend to intersect the rectangle, so a new shape is always created.Does anyone have any ideas how I would traverse the lines and intersection points to create the bounded polygons created as each new line is added? I need to be able to color each piece of the created polygon differently.

Currently I create lines and intersections which I associated with each other. I then tried traversing all intersections on line switching to the intersecting line at each intersection point. I compare the distance to the origin to determine the best point to chose on the intersecting line, but this is problematic. Is there an easier way to do this?

[736 byte] By [angry.jima] at [2007-11-27 1:39:44]
# 1
I don't completely understand your goals. Could you post your current code here?
AlexeyUshakova at 2007-7-12 0:53:10 > top of Java-index,Security,Cryptography...
# 2
I figured it out. You essentially have to keep Split the lines into segmentsIterate through the list of segmentsTrack of the origin pointDetermine if a candidate point crosses any other line.etc.
angry.jima at 2007-7-12 0:53:10 > top of Java-index,Security,Cryptography...