You are viewing the course site for a past offering of this course. The current offering may be found here.
Lecture 2: Digital Drawing (51)
thecatherinehuang

In practice, given any three points there are 6 possible permutations (012, 021, 102, 120, 201, 210). Notice that because it's a triangle, you can either go in a clockwise way (021, 102, 210) or in a counter-clockwise way (012, 120, 201). In the counter-clockwise direction as demonstrated in lecture, the check is that L0(sx,sy)>=0, L1(sx,sy)>=0, and L2(sx,sy)>=0 must all be satisfied for the point to be inside the triangle. On the other hand, if we happen to traverse the points in a clockwise manner, the check is the opposite L0(sx,sy)<=0, L1(sx,sy)<=0, and L2(sx,sy)<=0.

This observation is nice because (I think) in the counter-clockwise orientation, it's impossible to satisfy all three inequalities [L0(sx,sy)<=0, L1(sx,sy)<=0, and L2(sx,sy)<=0] that form the check for the clockwise direction. This prevents against traversing in a counter-clockwise manner, satisfying the <= inequalities, but not being inside the triangle. So no matter what order we traverse the points, if one of these two checks are satisfied, the point lies inside the triangle.

This is really nice and is only a property for triangles-- another reason why we choose to use triangles for rasterization.

UncooleBen

Yeah I agree with Huang's comment. Testing >= 0 will only work for counter-clockwise traversal. We can summarize the test as "having three inequality in the same direction" to include the other situation.

Staffrishiu

@thecatherinehuang @UncooleBen great points! this property of both orders being ok comes up in the first project and is key to implementing this test

You must be enrolled in the course to comment