title: Line-Line intersection in Python with numpy
body: <p>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 <a href="https://www.youtube.com/watch?v=kCyoaidiXAU&amp;t=313s" rel="nofollow noreferrer">https://www.youtube.com/watch?v=kCyoaidiXAU&amp;t=313s</a>).</p>
  
  <p>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.</p>
  
  <p>With that, it's possible to formulate the line as:<br>
  L1 = r0 (known point) + t (unknown variable) * V (direction vector)</p>
  
  <p>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.</p>
  
  <p>For example:</p>
  
  <pre><code># 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) # --&gt; [0,3]
  v2 = (B[0].x - B[1].x, B[0].y, B[1].y) # --&gt; [-4,0]
  
  L1 = A[1] + x * v1
  L2 = B[1] + y * v2
  </code></pre>
  
  <p>Now, I would solve this manually by solving L1 for x:</p>
  
  <pre><code>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  &amp;  3x = 2
  y = 1/2   &amp;   x = 2/3
  </code></pre>
  
  <p>But I have no idea how to tell numpy/python how to solve for x and y.</p>
  
  <p>Any help or guide in the right direction would be much appreciated.</p>