Eugeneโs answer works, but it requires a lot of effort without the support of the library: calculate the full Voronoi diagram and the additional scan line algorithm. It is easier to list for both sets of points the points that Voronoi cells intersect the dividing line in order, and then check all pairs of points whose cells intersect using the linear time merge step.
To calculate the necessary fragment of the Voronoi diagram, suppose that the x axis is a dividing line. Sort the points in the set using the x-coordinate, discarding points with a larger y than any other point with an equal x. Start scanning the points in the x-coordinate order by clicking them on the stack. Between clicks, if the stack has at least three points, say p, q, r, when r was pressed most recently, check if the bisecting pq line intersects the dividing line after the bisecting qr line. If so, drop q and repeat the test with the new triple. Crude ASCII art:
Case 1: retain q ------1-2-------------- separating line / | p / | \ | q-------r Case 2: discard q --2---1---------------- separating line \ / p X r \ / q
source share