I found this challenge problem which states the following :
Suppose that there are n rectangles on the XY plane. Write a program to calculate the maxi
How about the following algorithm:
RES = 0 // maximum number of intersections
CORNERS[] // all rectangles corners listed as (x, y) points
for A in CORNERS
for B in CORNERS // optimization: starting from corner next to A
RES = max(RES, CountIntersectionsWithLine(A.x, A.y, B.x, B.y))
return RES
In other words, start drawing lines from each rectangle corner to each other rectangle corner and find the maximum number of intersections. As suggested by @weston, we can avoid calculating same line twice by starting inner loop from the corner next to A
.