Lecture 5: Texture Mapping (19)
woojinko

Remember that this line equation is also equivalent to the dot product of the vector from P to (x,y) and the normal vector to PQ. I found this form much easier to implement in code for project part 4!

hershg

If anyone's having confusion with this, here's some more worked out detail:

$PQ = \begin{bmatrix} x_q - x_p \\ y_q - y_p \end{bmatrix}$

To take the clockwise direction normal,

$Normal(\begin{bmatrix} a \\ b \end{bmatrix}) = \begin{bmatrix} -b \\ a \end{bmatrix}$

Thus,

$Normal(PQ) = \begin{bmatrix} -(y_q - y_p) \\ x_q - x_p \end{bmatrix}$

$L_{PQ}(x, y) = (Line from P to (x,y)) \cdot Normal(PQ)$

$= \begin{bmatrix} x - x_p \\ y - y_p \end{bmatrix} \cdot \begin{bmatrix} -(y_q - y_p) \\ x_q - x_p \end{bmatrix}$

$= -(x - x_p)(y_q - y_p) + (y - y_p)(x_q - x_p)$

Which matches what's in the slide!

If we're looking in the counter-clockwise direction instead, we simply negate our expression for $L_{PQ}(x,y)$

You must be enrolled in the course to comment