I'm creating a program which requires me to get intersection point of two lines. I have tried using different formulas but none of them works perfectly for me. Following is one example which I found on math.stackexchange.
x = ((x1 - x2) * (u1 * v2 - u2 * v1) - (u2 - u1) * (x2 * y1 - x1 * y2)) / ((v1 - v2) * (x1 - x2) - (u2 - u1) * (y2 - y1)) y = (u1 * v2 * y1 - u1 * v2 * y2 - u2 * v1 * y1 + u2 * v1 * y2 - v1 * x1 * y2 + v1 * x2 * y1 + v2 * x1 * y2 - v2 * x2 * y1) / (-1 * u1 * y1 + u1 * y2 + u2 * y1 - u2 * y2 + v1 * x1 - v1 * x2 - v2 * x1 + v2 * x2)
given these points A = (0.0, 0.0), B = (0.0, 50.0), C = (20, 0), D = (70.0, 50) my lines are AB and CD. There is no intersection between above two lines. with above method it gives me following answer: (0.0, -20.0). Do you know of some method that makes sure that the line is not extended to infinity?