There is a ball starting at point $A$ going forward in the direction towards point $B$ (so it moves along the $(AB)$ line).
A wall is represented by its two ends $W_1$ and $W_2$.
I have to solve in a general way the question "Will the ball hit the wall ?". The question seemed quite simple at first but there are a lot of particular possibilities.
So either the vectors are colinear and $(x_B-x_A)*(y_{W_2}-y_{W_1}) = (y_B-y_A)*(x_{W_2}-x_{W_1})$, and if they are, they can either be on the same line or not.
So we check if $y_{W_1}-y_A =(y_B-y_A)/(x_B-x_A)*(x_{W_1}-x_A)$ and if it's true, we then have to check if $\overrightarrow{AB}$ points towards the wall.
So I tried to compare the $x$ and $y$ coordinates but it doesn't seem sufficient to conclude if point B is between $W_1$ and $W_2$. And this is just the simple case when they are parallel and it becomes more complicated then to generally check if the ball will hit (we also have to check if the intersecting point is between the ends of the wall but that's easy).
If they're not parallel, I've determined precisely the possible intersection points (with all the particular cases of the line being vertical or horizontal and then we can't use the equations to check the intersection).
How can we check if the vector really points towards the wall ? (when they're parallel and in a general way ?)
Is there a more elegant and general way to solve the problem ?
If the lines are not parallel, then you can uniquely calculate the intersection point between the complete straight line through $A$ and $B$ and the complete straight line through $W_1$ and $W_2$. Let's call it $I$. Then all which is left to do is to check that $I$ is both between $A$ and $B$, and between $W_1$ and $W_2$. Since you already know that $I$ is on the straight line through $A$ and $B$, this is easily done by checking that for a single arbitrary coordinate in which $A$ and $B$ differ, the corresponding value for $I$ is in between, and the same for $W_1$ and $W_2$.
If the lines are parallel, then all you have to check is whether at least one of the following relations are true: $d(A,W_1)+d(W_1,B)=d(A,B)$, $d(A,W_2)+d(W_2,B)=d(A,B)$, $d(W_1,A)+d(A,W_2)=d(W_1,W_2)$ or $d(W_1,B)+d(B,W_2)=d(W_1,W_2)$ where $d(P,Q)$ is the distance between the points $P$ and $Q$. If any of them is true, the point "hits" the wall (actually, moves at least partially along it), otherwise it doesn't.
If you do numerical calculations, you of course want to take into account that you may have rounding errors, and therefore the equalities may not be exact equalities. That is, you should test whether the absolute difference is smaller than some pre-defined value epsilon.