An optimal algorithm for intersecting line segments in the plane