code with help functions for calculating the intersection of the lines