Find a line that crosses multiple line segments I'm looking for a formula, or algorithm, that would allow me to figure out if there's a line that cross multiple line segments (those are always parallel to the y axis), and if there is, the equation for that line.
For example, in the following diagram, I'm looking for any line that touches the 4 vertical bar, such as the red line shows. It can touch the bars anywhere.

I can figure out how to do it with 3 line segments, but anything over that I have no idea.
I'm also not a mathematician so I probably got most terminology wrong.
EDIT: a possible approach is recursive, by drawing the bow-tie of possible lines for the left-most two segments, and seeing if the third segment touches the bow-tie. If so, create a narrower bow-tie of acceptable lines for the first three, and so on.



I don't know your precise requirements in handling this problem, but I can suggest a "practical" (engineer-wise) approach to it.
The concept is that if there is a set of lines which crosses all or most of the segments, then the least-squares regression line through the end points of the segments will be "close" to that set.
Since you are actually interested to pierce the most of the segments, the smaller ones having to you the same interest as the larger, you shall actually perform a weighted regression, giving higher weight to smaller segments. You could for instance duplicate the points at regular distance over each segment (every $1/3$) or triplicate, etc. and then perform the regression.
You could also perform a non-linear regression, e.g. quadratic, and then judge from the concavity of the obtained parabola if a line going through all segments is attainable.
