Unit - 2 Windowing & Clipping
Unit - 2 Windowing & Clipping
Transformations from world to device coordinates involve translation, rotation and scaling operations
and procedures for deleting those parts of the picture that are outside the limits of a selected display area.
Yv – Yvmin = Yw – Ywmin
Yvmax – Yvmin Ywmax – Ywmin
Solve these expression for the viewport position (Xv, Yv), we can rewrite above equation as:
➢Every line end point in a picture is assigned a four digit binary code called a region code.
➢Region code identifies the location of the point relative to the boundaries of the clipping rectangle.
Bit Bit Bit Bit
4 3 2 1
Above / Below / Right Left
Top Bottom
Region Code
LINE CLIPPING
Midpoint Subdivision Algorithm:
The line is divided at its midpoint into two shorter line segments. Lines which cross one or two
boundaries, we have to clip and fall in category 3. Category 1 lines are completely in the visible region
and lines in category 2 are not visible and lie outside the window. Each segment in category 3 is again
divided into shorter segments and categorized.
The bisection process and categorization is continued until each line segment that encompasses an
intersection point across window boundaries reaches a threshold for line size and all other segments are
either in category 1(visible) or in category 2(invisible). The midpoint coordinates (Xm, Ym) of a line
joining (X1, Y1) and (X2, Y2) are given by Xm = (X1 + X2) / 2 and Ym = (Y1 + Y2) / 2. In the above
figure we can determine the two intersection points M1 and M2 with 7 bisections using the midpoint
subdivision algorithm.
AREA CLIPPING:
To clip polygons, we cannot use the line clipping algorithm, we need to modify the line – clipping
procedures. A polygon processed with a line clipper may be displayed as a series of unconnected line
segments.
For polygon clipping, we require an algorithm that will generate one or more closed areas that can fill
the area. The output of a polygon clipper should be a sequence of vertices that defines the clip polygon
boundaries.
SUTHERLAND – HODGEMAN POLYGON CLIPPING:
Sutherland - Hodgeman clipping is used for polygon clipping. The algorithm operates on the vertices of
the polygon. The simple problem is to clip a polygon against a single clipping edge. We clip the polygon
on all four edges by clipping the entire polygon against one edge, then taking the resulting polygon and
clipping against a second edge and so on for all four edges.
Four possible situations while processing
1. If the first vertex is outside the window boundary and the second vertex is inside, both the intersection
point of the polygon edge with the window boundary and the second vertex are added to the output
vertex list.
2. If both vertexes are inside window boundary. Then only second vertex is added to the output list.
3. If the first vertex is inside the window and second is an outside window. The edge which intersects
with window is added to output list.
4. If both vertices are the outside window, then nothing is added to output list.
There are several techniques that can be used to provide text clipping in a graphics package. The
different methods are:
Areas with curved boundaries can be clipped. Curve – clipping procedures will involve nonlinear
equations. The bounding rectangle for a circle or other curved object can be used first to test for overlap
with a rectangular clip window. If the bounding rectangle for the object is completely inside the window,
we save the object. If the rectangle is determined to be completely outside the window, we discard the
object.
EXTERIOR CLIPPING:
Till now procedures were used to clip a picture to the interior of a region by eliminating everything
outside the clipping region. That is, we save only the inside region. In some cases, we want to do the
reverse, that is, we want to clip a picture to the exterior of a specified region. The picture parts to be
saved are those that are outside the region. This is referred to as “exterior clipping”.
Example: design of page layouts in advertising or publishing applications or for adding labels or design
patterns to a picture.