Algorithmus zum Ausfüllen des Dreiecks

Ich denke über Rasterization Triangle-Algorithmus. triangle_rasterization_lesson )

Ich habe den folgenden Code geschrieben:

void triangle(int xa, int ya, int xb, int yb, int xc, int yc, TGAImage &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<=xb; x++)
    {
        for (int y = ya; y<=yb; y++)
        {
            line(xc, yc, x, y, image, white);
        }
    }
}

Mittriangle(100, 100, 100, 400, 400, 100, image, red); es funktioniert einwandfrei. Aber wenn ich die Koordinaten von X (xa, ya) und Z (xc, yc) vertausche, fülle ich mein Quadrat nicht aus.

Mittriangle(70, 50, 200, 100, 20, 150, image, red); es zeichnet Dreieck, aber FüllungErgebnisse außerhalb der Grenzen.

Wo ist das Problem

Antworten auf die Frage(4)

Ihre Antwort auf die Frage