I have a relatively simple question, I know the answer but I can't seem to find the right implementation using Python and Numpy. The idea is, I have two lines and I need to find the virtual intersection point (I used the example from https://www.youtube.com/watch?v=kCyoaidiXAU&t=313s).
Both lines have the form of r = r0 + t*V, with r0 as position vector (a point that the line passes through), t a variable and V, the direction vector. Direction vector V can be found simply by finding the vector through both points of the line, e.g. V = A - B.
With that, it's possible to formulate the line as:
L1 = r0 (known point) + t (unknown variable) * V (direction vector)
Now, I can easily find t manually, but I have no clue how to tell Python.. I tried numpy.linalg.solve, but that gives me a matrix, while I need a single value.
For example:
# Line A and Line B that intersect somewhere
A = LineString([(4., 0.), (4., -3.)])
B = LineString([(6., 2.), (10., 2.)])
# direction vectors for line A and B
v1 = (A[0].x - A[1].x, A[0].y, A[1].y) # --> [0,3]
v2 = (B[0].x - B[1].x, B[0].y, B[1].y) # --> [-4,0]
L1 = A[1] + x * v1
L2 = B[1] + y * v2
Now, I would solve this manually by solving L1 for x:
L1 = [4, 0] + x * [0, 3] = [4, 3x]
L2 = [6, 2] + y * [-4, 0] = [6-4y, 2]
# finding intersection point by solving L1 = L2
4 = 6-4y & 3x = 2
y = 1/2 & x = 2/3
But I have no idea how to tell numpy/python how to solve for x and y.
Any help or guide in the right direction would be much appreciated.