A hint: this problem is basically a dual of the convex hull problem.
Solution: If you treat each line y=ax+b
as a point (a,b)
, and add an additional "point" at (0, -infinity)
, you should be able to feed this into any 2D convex hull algorithm and get a correct solution.
Note: Conversely, any solution of this problem can also be used to build a 2D convex hull algorithm of the same O().
Edit: A request to prove it...
For a point (x,y)
to be above a particular line y=ax+b
, you have the inequality ax - y + b > 0
.
This inequality is also equivalent to the point (-a,b)
being above the line (b)=x(-a)+y
, where x is the slope and y is the intercept.
This duality allows us to treat points as lines and lines as points: any proof or algorithm on points and lines can be mapped into an equally valid one with lines and points reversed.
In this case: the convex hull of a set of 2D points determines the "extreme" points which are not convex combinations of others, as well as the lines between successive extreme points. Correspondingly, the dual version of the convex hull determines those "extreme" lines which are not convex combinations of others, as well as the points of intersection between successive extreme lines. This is the envelope of the given set of lines.
The dual of the convex hull gives you both the upper and lower envelope of the input line set. Since you only want the upper envelope of your lines, you need to add a line lower than any possible regular line to eliminate the lower envelope. Alternately, you can look through the solution and choose only intersections with increasing slope.
Conversely, any solution of this problem can be used to determine the upper convex hull of a set of points. Running it twice, once for lines {(a,b)} and again for lines {(-a,-b)}, will give you a full convex hull.