title: Algorithm to fill triangle
body: <p>i'm thinking about rasterization triangle algorithm. ( <a href="https://github.com/ssloy/tinyrenderer/wiki/Lesson-2:-Triangle-rasterization-and-back-face-culling" rel="nofollow">triangle_rasterization_lesson</a> )</p>
  
  <p>I wtote the following code:</p>
  
  <pre><code>void triangle(int xa, int ya, int xb, int yb, int xc, int yc, TGAImage &amp;image, TGAColor color)
  {
      line(xa, ya, xb, yb, image, color);
      line(xa, ya, xc, yc, image, color);
      line(xb, yb, xc, yc, image, color);
      for (int x = xa; x&lt;=xb; x++)
      {
          for (int y = ya; y&lt;=yb; y++)
          {
              line(xc, yc, x, y, image, white);
          }
      }
  }
  </code></pre>
  
  <p>With <code>triangle(100, 100, 100, 400, 400, 100, image, red);</code> it works properly.
  But if i swap X(xa, ya) and Z(xc, yc) coordinates to doesn't fill my square.</p>
  
  <p>With <code>triangle(70, 50, 200, 100, 20, 150, image, red);</code> it draws triangle, but filling <a href="http://i.stack.imgur.com/S3xEA.png" rel="nofollow">comes out of bounds.</a></p>
  
  <p>Where is the problem?</p>