Previous | Next --- Slide 63 of 71
Back to Lecture Thumbnails
ziqichen

It seems the vertices should be given in counterclockwise order to make the checking equations work; if clockwise, the signs should be reversed. Is that correct?

motoole2

Very nice observation---you're right! If we swap the order of the vertices, this changes the meaning of our function E_i(x,y): E_i(x,y) < 0 represent points outside an edge, and E_i(x,y) > 0 represent points inside an edge.

Any point inside a triangle must satisfy either E_i(x,y) > 0 for all three edges or E_i(x,y) < 0 for all three edges, regardless of the order of the vertices. Note that for any point outside the triangle, the sign of E_i(x,y) will be different for one of the edges.

There's another tidbit of information here. The orientation of the vertices can also be used to express whether we are seeing the front of a triangle, or its back. For example, if E_i(x,y) > 0 for all three edges i (clockwise order of vertices), then the point is on the front of a triangle; else if E_i(x,y) < 0 for all three edges i (counter-clockwise order of vertices), then the point is on the back of a triangle; else, the point is not on the triangle at all. The orientation of a triangle can be used to check if a triangle is visible (e.g., facing a camera), and is known as back-face culling. When enabled, back-face culling ensures that the only triangles that are being rasterized have vertices in counter-clockwise order (by default). Hence, why we can assume clockwise order here.