Given a set S of line segments and an additional segment L, I'm looking for a procedure that determines which of the line segments in S is nearest to L. My first thought was to compute the distance between the points of L and the points of each line segment in S, however it can be tricky as illustrated in the following figure:
Let's say that L is the blue line, I want my method to point out that the green one is the nearest, but computing the distance between the points in such example may not provide the intended result.
Therefore my question is: which is the simplest (and correct) way to address this problem.
Thank you so much for your help.
edit: note that the lines are not always parallel, horizontal nor straight