Page 141 - DCAP504_Computer Graphics
P. 141

Computer Graphics



                          A region code is assigned to every point of a line depending on its position (x,y). Starting from the
                          leftmost bit,
                          Bit 1: sign(y-y max) = Endpoint is above the window

                          Bit 2: sign(y min-y) = Endpoint is below the window
                          Bit 3: sign(x-x max) = Endpoint is to the right of the window
                          Bit 4: sign(x min-x) = Endpoint is to the left of the window
                          Here, sign(a) is set to 1 if a is positive otherwise a is set to 0. The point with code 0000 is always inside
                          the window.

                          2.   Step 2: If the endpoints of the line lie in the region with codes 0000 then the line is visible. The line
                              is not visible if the bitwise logical AND of the codes is not 0000. Thus, this line is considered as
                              clipping candidate.


                                                        Figure 9.5: Clipping Candidate




















                          In case of a line in category 3 (Clipping candidate), you need to find the point that intersects with one of
                          the boundaries of the clipping window. First, you need to select the endpoint of the line (x 1, y 1) that is
                          outside the window whose region code is not 0000. Then, you need to select an extended boundary by
                          observing those boundary lines that are candidates for intersection. Here, the selected endpoint is
                          pushed across in order to change ‘1’ in its code to ‘0’. This indicates that:

                          If Bit 1 is 1, then intersect with line y = y max
                          If Bit 2 is 1, then intersect with line y = y min
                          If Bit 3 is 1, then intersect with line x = x max
                          If Bit 4 is 1, then intersect with line x = x min
                          In figure 9.5, the line LM falls under the clipping candidate category. If endpoint L is selected, then the
                          intersection point is computed by selecting the bottom boundary line y = y min. If endpoint M is selected,
                          then either the top boundary line y = y max or the right boundary line x = x max is selected for computing
                          intersection.  The co-ordinates of the intersecting points are:


                                             x i = x min or x max                           if the boundary line is vertical
                                             y i = y 1 + m (x i + x 1)







                          134                     LOVELY PROFESSIONAL UNIVERSITY
   136   137   138   139   140   141   142   143   144   145   146