criterion for two line segments intersecting
You need to know about the orientation test.

For any three points, compute the determinant

$$\Delta_{123}=\left| \begin{array}{ccc}
x_1 &amp; y_1 &amp; 1 \\
x_2 &amp; y_2 &amp; 1 \\
x_3 &amp; y_3 &amp; 1 \end{array} \right|.$$

This is twice the signed area of the triangle $123$. When it is $0$, it tells you that the three points are aligned. Otherwise, it tells you on what side of the line joining two points the third lies.

In your case, there is an intersection if $1$ and $2$ are on either sides of $34$, while $3$ and $4$ are on either sides of $12$:
$$(\Delta_{134}&gt;0)\ne(\Delta_{234}&gt;0)\land(\Delta_{123}&gt;0)\ne(\Delta_{124}&gt;0).$$

It is up to you to decide what to do in cases of perfect alignments.

As an extra goodie, the $\Delta$'s can be used to compute the coordinates of the intersection. (Let $P$ be the intersection point, interpolated along the segment $P_1P_2$: $P=(1-t).P_1+t.P_2$; it is easy to show that $(1-t)\Delta_{134}+t\Delta_{234}=0$ and to find the value of $t$.)