title: Divide quadrilateral into grid in Java
body: <p>I have a convex quadrilateral. I know the four points, and I have its four lines in the format <code>mx + b</code> (from the top going clockwise). <code>Quadrilateral</code> is a class shown below:</p>
  
  <pre><code>import java.awt.Point;
  import java.awt.Polygon;
  
  public final class Quadrilateral extends Polygon {
      private static final long serialVersionUID = 794866732073166739L;
      public final Point p1, p2, p3, p4;
      public final Line l12, l23, l34, l41;
  
      public Quadrilateral(Point p1, Point p2, Point p3, Point p4) {
          super(new int[] { p1.x, p2.x, p3.x, p4.x }, new int[] { p1.y, p2.y,
                  p3.y, p4.y }, 4);
          this.p1 = p1;
          this.p2 = p2;
          this.p3 = p3;
          this.p4 = p4;
          this.l12 = Quadrilateral.getLine(p1, p2);
          this.l23 = Quadrilateral.getLine(p2, p3);
          this.l34 = Quadrilateral.getLine(p3, p4);
          this.l41 = Quadrilateral.getLine(p4, p1);
      }
  
      public static final Line getLine(Point p1, Point p2) {
          if (p1.x &gt; p2.x) {
              return Quadrilateral.getLine(p2, p1);
          } else {
              int x1 = p1.x;
              int x2 = p2.x;
              int y1 = p1.y;
              int y2 = p2.y;
              int xdiff = x2 - x1;
              int ydiff = y1 - y2;
              double m = (double) ydiff / (double) xdiff;
              double b = y1 - m * x1;
              return new Line(m, b);
          }
      }
  
      public Quadrilateral[][] grid(int x, int y) {...?...}
  }
  </code></pre>
  
  <p>What I want to do is to divide an instance of <code>Quadrilateral</code> into an <code>x</code> by <code>y</code> grid of Quadrilaterals, sorted in a <code>Quadrilateral[][]</code>. How would I do this efficiently?</p>