Chapter 12
Clipping

12.1 Finite View Volume

Add the following planes.

                                  ---
                           --------
                    -|------ --- |
             -|------|     ---   |
      ---|||||||||||||||||||||||||||
     -||||---------------     ---
         ----- ----    |    ---
hither       ------    | ---
                  --------
        window        ---
                    yon                   yon        ---      ---
                --------------------|--
   -----------------------|         |
hither-------------            |         |
   |        |             |         |
   |        |      ||||||||---------|----
   |  |||||||||-------------
----||----------

Equations

12.2 Clipping After Projecting

                            yon       ----      ---
                         ---------------------|-
hither      ----------------------- |         |
        -----|    ----|             |         |
             |        |             |    |    |   -
             |        |     |||||||||---------|----
             | |||||||||--------------
        ------|----------

12.3 Cohen-Sutherland Cubic 3D Line Clipper

                 |||        |||
         zmax|||||------||||||--
zmin    ||||||     ||||||   |
ymax  ||||-------||||--     | |
        |          |      ||---
        |          |  |||||
 ymin  |||--------|||||-

      xmin        xmax                   -----------------------------------------
             ----                                  |---  |
         ----                                  ----|     |
     -----                                 ---|-   |     |
  |------------|-----------|----------------  |    |     |
  |            |           |            |     |    |01   |
  1001**1000**1010**---------------------     00   |     |
  |            |           |            |  0  |    | ----
  0001**0000**0010**       |            |1    |  -----
  ---------------------------------------    -|---
  0101**0100**0110**       |            | ----
  ----------------------------------------

|-----|--------|---------|--------|----------
updown###|##right##|###left###|#front##|##back###|
|#####|########|#########|########|#########|
---------------------------------------------

 
 B1 = outcode(P1)
 B2 = outcode(P2)
 REPEAT
   CASE                      trivial test
     ( B1 OR  B2 )  = 000000 : accept
     ( B1 AND B2 ) <> 000000 : reject
     ELSE                     intersect
       IF B1 <> 000000  THEN
         P1 := (P1,P2) intersect
                side in B1
         B1 = outcode(P1)
       ELSE
         P2 := (P1,P2) intersect
                side in B2
         B2 = outcode(P2)
   END
 UNTIL clipping is impossible

12.4 Liang-Barsky Cubic 3D Line Clipper

 

|         |
|         |
|         |
t=1o         |
o--------------------
|         |
|         |
Tmax•||       |
--|•||---------------
Tmin    |||  |
|      ||||
|        |o|
           |||
             ||
              o t = 0

z    -||||-------||||-
max||||      ||||||
zmin|-------|||||    |
ymax      |||        |||
|        |    ||||---
|        ||||||
ymin------||||--
x      x
min       max
 Tmin := 0
 Tmax := 1
 dX := X2-X1
 adjust(Xmin-X1, dX)
 adjust(X1-Xmax,-dX)
 dY := Y2-Y1
 adjust(Ymin-Y1, dY)
 adjust(Y1-Ymax,-dY)
 dZ := Z2-Z1
 adjust(Zmin-Z1, dZ)
 adjust(Z1-Zmax,-dZ)
 IF Tmin > 0 THEN
   X1 := X1 + round(dX * Tmin)
   Y1 := Y1 + round(dY * Tmin)
   Z1 := Z1 + round(dZ * Tmin)
 IF Tmax < 1 THEN
   X2 := X2 + round(dX * Tmax)
   Y2 := Y2 + round(dY * Tmax)
   Z2 := Z2 + round(dZ * Tmax)

12.5 Sutherland-Hodgman Polygon Clipper

--|   -------|   ---------|   ---------|
clipclipclip |   |clip  |   |clip    |   |clip    |   -||||||||
in --|||      --|||        --|||        --|||out   |--
updownright |   |left  |   front    |   back     |    |||||||
---   -------    ----------   ---------

 
 FOR clip_side := up, down,
           right, left, front, back DO
   CLIP polygon AGAINST clip_side

              |
             ||
 |---------|||
 |         ||
 |         ||
 |        ||
||       |||
||      ||||
 |||    ||||
 -----------
   ||||||
     ||||
     ||||
       |   |----------||
 |          ||
 |         ||
 |        |||
||       ||||
|||      ||||
 |||||  ||| |
 -----------
     |||||
      ||||
       ||   |----------||
 |          ||
 |         |||
 |         ||
 |        |||
||       ||||
 |||    |||||
 -----------    |----------|
  |         ||
  |        |||
  |        |||
|||       || |
  |||    ||| |
  ||||| |||| |
  -----------  |----------|
|         ||
|         ||
|        |||
|       || |
||     ||| |
||||| |||| |
-----------

           |
    |      |
####|######|
####|######|
####|######|
###|||#####|
####•######|
           |
           |        |
       |
#######|
#######|
#######|
#######|
#------•-----||
       |
       |        |
       |      ||
#######|      |
#######|      |
#######|      |
#######|      |
#######|
       |
       |         |
•||----•-------
#######|
#######|
#######|
#######|
#######|
       |
       |