I am creating a bit of a weird program, but the basic premise is that I have defined a 2 dimensional scenario and I want to project it (using perspective projection) onto a 1 dimensional viewing line that is directly in front of the player. This is shown in the first picture. I have this working for a single line, but I would like to add as many lines as I want and make them display in a way that makes sense. This means that lines that are in front of other lines need to appear that way. The problem I have is more of a math question, but basically the question is: given a location of the player, and some set of lines defined by 2 points each, how would I determine in which order to project the lines to the viewing line?
In the second image, the program needs to determine to project line A onto the viewing line first. This allows B, when projected, to cover up the part of A that doesn't need to be seen. I cannot think of a way to determine which lines to project first, because for every idea I think of, I can come up with an example that it will not work with. For example, if we just do some sort of distance formula to let's say, the midpoint of every line, that will not work for something like in the third picture. In this case, B should be projected first so A can cover up the part of B.
Whatever the solution is, it must also work for any amount of lines in front of the player, so I just need the order in which to display the lines. Thank you.