title: Line Segments Intersection(intersection Point)
body: <p>I have created a function to calculate the intersection point of two line segment .</p>
  
  <p>Unfortunantly the code below dosen't work if one of the segment is verticale</p>
  
  <pre><code>    public static Point intersection(Segment s1, Segment s2) {
      double x1 = s1.getP1().getX();
      double y1 = s1.getP1().getY() ;
      double x2 = s1.getP2().getX();
      double y2 = s1.getP2().getY() ;
      double x3 = s2.getP1().getX();
      double y3 = s2.getP1().getY();
      double x4 = s2.getP2().getX();
      double y4 = s2.getP2().getY();
  
      double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
      if (d == 0) {
          return null;
      }
      double xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
      double yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;
      Point p = new Point(xi, yi);
      if (xi &lt; Math.min(x1, x2) || xi &gt; Math.max(x1, x2)) {
          return null;
      }
      if (xi &lt; Math.min(x3, x4) || xi &gt; Math.max(x3, x4)) {
          return null;
      }
      return p;
  }
  </code></pre>
  
  <p>the problem when i have a vertical line segment , this formula</p>
  
  <pre><code>double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  </code></pre>
  
  <p>is equal to 0 and the method return null.</p>
  
  <p>How can I handle this exception.</p>
  
  <p>Thank you</p>