5
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam September 30, D Clipping 5/14 If we can neither trivial reject nor accept, divide and conquer: subdivide line into two segments, then can T/A or T/R one or both segments: –use a clip edge to cut the line –use outcodes to choose edge that is crossed: if outcodes differ in the edge’s bit, endpoints must straddle that edge –pick an order for checking edges: top – bottom – right – left –compute the intersection point; the clip edge fixes either x or y, can be substituted into the line equation –iterate for the newly shortened line –“extra” clips may happen, e.g., E-I at H Cohen-Sutherland Algorithm Clip rectangle D C B A E F G H I

9
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam September 30, D Clipping 9/14 Now we can solve for the value of t at the Intersection of P 0 P 1 with the edge E i : N i [P(t) – P E i ] = 0 First, substitute for P(t): N i [P 0 + (P 1 – P 0 )t – P E i ] = 0 Next, group terms and distribute the dot product: N i [P 0 – P E i ] + N i [P 1 – P 0 ]t = 0 Let D be the vector from P 0 to P 1 = (P 1 – P 0 ), and solve for t: Note that this gives a valid value of t only if the denominator of the expression is nonzero. For this to be true, it must be the case that: N i  0 (that is, the normal should not be 0; this could occur only as a mistake) D  0 (that is, P 1  P 0 ) N i D  0 (edge E i and line D are not parallel; if they are, no intersection). The algorithm checks these conditions. C-B/L-B Param. Line Clipping-2