[...] but I can't understand how it works. Can someone please try and explain it?

The method is this: There a re 2 line segments **p**_{0}**p**_{1} and **p**_{2}**p**_{3} given. They can be expressed by using a ray equation (i.e. directed line) when the independent variable of the ray is restricted. In this case

**r**_{01}( s ) := **p**_{0} + s * ( **p**_{1} - **p**_{0} ) w/ 0 <= s <= 1

**r**_{23}( t ) := **p**_{2} + t * ( **p**_{3} - **p**_{2} ) w/ 0 <= t <= 1

**r**

_{01}( s ) =

**r**

_{23}( t )

It works perfectly. [...]