A coworker gave me this problem to try out my knowledge:
Consider two points, 1 and 2, having coordinates (x1, y1) and (x2, y2), respectively. In the same plane as these two points is a vertical line whose top and bottom are represented by (xTop, yTop) and (xBot, yBot), respectively. The two points may be on opposite sides of the wall, on the same side of the wall, or directly above/below the wall. For simplicity, neither of the points can be directly on the wall. A line is drawn from point 1 to point 2; if an intersection on the wall (the vertical line) occurs, it will occur at point (xInt, yIint).
Given two points and one wall, write an algorithm to determine if the two points can see one another. This can only occur if the line drawn from point 1 to point 2 does not touch the wall.
I correctly identified that if both points' x-values are less/greater than that of the wall's, they can see one another. The same goes for the y-values. I believe that there is a lot of geometry involved in this problem. But, I'm an old man, just getting back into programming for fun and this is really trying for me to comprehend. Any help would be immensely appreciated. Thank you.
-Jon N.