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

The slides only mention the rule to determine whether the center of a pixel is on the "inside" or "outside" of a line, but in order to tell whether the pixel is in a triangle, we also need to know the relative position of the line and pixel.

For example, if we consider the line P1->P2, the inner point is when L(x,y)<0. But if we consider line P2->P1, then L(x,y)>0. But how can we know whether L should be positive or negative?

An easy way is using P3. We know P3 must be an inner point, so whatever P1P2 or P2P1 we used, we bring in L(x3, y3) and find the sign. Then all points with the same sign of L(P3) will be the correct side of the inner points.

CeHao1
  1. Like, get L of (P1, P2).
  2. Then calculate s12 = sign(L(P3))
  3. For all points P, inside_flag_12 = (L(P) * s12) > 0

When we do not need to manual for every points, but processing the whole matrix to know the flag of each point.

  1. finally, in_flag = flag12 && flag23 && flag13 we don't need to worry about the difference of line P1P2 or P2P1.
JefferyYC

I like the observation from @CeHao1 that the 3rd point "must be an inner point" and the heuristics of determining the correct sign of the line function. Just to add on, on a more mathematical level, we are drawing a perpendicular vector that is either (-dY, dX) or (dY, -dX), one pointing inward to the triangle and the other outward from the triangle. We want our inner points to have positive inner products with the correct perpendicular vector. And @CeHao1's suggestion is an easy way to find which perpendicular vector to use.

Staffajayjain

Great observations @CeHao1 @JeffreyYC! This intuition should be useful for project 1, or more generally whenever you don't know the clockwise / counterclockwise ordering of vertices in a triangle.

You must be enrolled in the course to comment