title: How to calculate the point of intersection between two lines
body: <p>I am attempting to calculate the point of intersection between lines for a Optical Flow algorithm using a Hough Transform. However, I am not getting the points that I should be when I use my algorithm for calculating the intersections.</p>
  
  <p>I save the Lines as an instance of a class that I created called <code>ImageLine</code>. Here is the code for my intersection method.</p>
  
  <pre><code>Point ImageLine::intersectionWith(ImageLine other)
  {
      float A2 = other.Y2() - other.Y1();
      float B2 = other.X2() - other.X1();
      float C2 = A2*other.X1() + B2*other.Y1();
  
      float A1 = y2 - y1;
      float B1 = x2 - x1;
      float C1 = A1 * x1 + B1 * y1;
  
     float det = A1*B2 - A2*B1;
     if (det == 0)
     {
          return Point(-1,-1);
     }
     Point d = Point((B2 * C1 - B1 * C2) / det, -(A1 * C2 - A2 * C1) / det);
     return d;
  }
  </code></pre>
  
  <p>Is this method correct, or did I do something wrong? As far as I can tell, it should work, as it does for a single point that I hard-coded through, however, I have not been able to get a good intersection when using real data.</p>