The answer to the question here https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect by Gareth Rees is the best explanation.
We need to expand this to fit the co-ordinates
From https://stackoverflow.com/a/565282/429476
$$ \begin{align} t= (q-p) \times \vec s / \vec r \times \vec s\