Given some horizontal line segments, I want to find a vertical line which intersects all horizontal line segments. The algorithm is supposed to report if no such line exists. Also, in case of multiple vertical lines, the desirable is to find the line which is least distant from the center of bounding box of all horizontal line segments.
I am sure there will be something of this sort in combinatorial geometry, but I am not able to find. Could anyone please give me some ideas on how could we do it.
Thanks in advance.
I would loop through all of your line segments and find the following values:
No line exists if minxend < maxxstart because there is no way to hit both of the
lines that contained those values.
Find the centerx of the bounding box:
The x value of your vertical line segment will have to be between maxxstart and minxend.
Choose a value that is closest to centerx, call this newx.
Your vertical line segment will go from (newx, ymin) to (newx, ymax).