Since we have a separation between the models and the image
created from those models, there can be parts of the model that
do not appear in the current view when they are rendered.
pixels outside the clip rectangle are clipped, and are not displayed.
can clip analytically - knowing where the clip rectangle is clipping can be done before scan-line converting a graphics primitive (point, line, polygon) by altering the graphics primitive so the new version lies entirely within the clip rectangle
can clip by brute force (scissoring) - scan convert the entire primitive but only display those pixels within the clip rectangle by checking each pixel to see if it is visible.
as with scan conversion, this must be done as quickly as possible as it is a very common operation.
clipping rectangle with corners (Xmin,Ymin) (Xmax,Ymax)
point is within the clip rectangle if:
Xmin <= X<= Xmax
Ymin <= Y<= Ymax
given a line segment, repeatedly:
both endpoints within clip rectangle
both endpoints outside clip rectangle IS NOT ENOUGH
both endpoints off the same side of clip rectangle IS ENOUGH
Clip rectangle extended into a plane divided into 9 regions
each region is defined by a unique 4-bit string
(the sign bit being the most significant bit in the binary representation of the value. This bit is '1' if the number is negative, and '0' if the number is positive.)
The frame buffer itself, in the center, has code 0000.
1001 | 1000 | 1010 -----+------+----- 0001 | 0000 | 0010 -----+------+----- 0101 | 0100 | 0110
For each line segment:
The full algorithm ( was? ) given (in C) in the red book ( ??? Edition ) as program
3.7 on p.105.
The full algorithm is given (in C) in the white book as figure 3.41 on p.116.
Unlike line-clipping where we selectively clipped against each edge, here we sucessively clip a polygon against all four edges of the clip rectangle
given a polygon with vertices V1, V2, ... Vn
and edges between vertices Vi and Vi+1, and from Vn to V1
for each of the four clipping edges
repeatedly for each vertex V = Vn,
V1, V2, ... Vn
given an edge from vertex s to vertex p
assume s has already been dealt with
output edges become new set of polygon edges
This algorithm can break a single polygon into multiple polygons connected by edges on the boundary of the clipping rectangle for display.
The full algorithm ( was? ) given (in C) in the red book ( ??? Ediiton ) as program
3.9 on p.114.
The full algorithm is given (in Pascal) in the white book as program 3.49 on p.128.
Clipping on Ymax edge:
the new vertex sequence is then checked against the Ymin edge and so on through the Xmax edge and the Xmin edge