[...] 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 p0p1 and p2p3 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
r01( s ) := p0 + s * ( p1 - p0 ) w/ 0 <= s <= 1
r23( t ) := p2 + t * ( p3 - p2 ) w/ 0 <= t <= 1
It works perfectly. [...]