unit -III computer graphics
unit -III computer graphics
Two dimensional viewing The viewing pipeline A world coordinate area selected for display is called a
window. An area on a display device to which a window is mapped is called a view port. The window
defines what is to be viewed the view port defines where it is to be displayed. The mapping of a part of a
world coordinate scene to device coordinate is referred to as viewing transformation. The two d imensional
viewing transformation is referred to as window to view port transformation of windowing transformation.
A viewing transformation using standard rectangles for the window and viewport
The viewing transformation in several steps, as indicated in Fig. First, we construct the scene in
world coordinates using the output primitives. Next to obtain a particular orientation for the window, we
can set up a two-dimensional viewing-coordinate system in the world coordinate plane, and define a
window in the viewing-coordinate system. The viewing- coordinate reference frame is used to provide a
method for setting up arbitrary orientations for rectangular windows.
Once the viewing reference frame is established, we can transform descriptions in world coordinates
to viewing coordinates. We then define a viewport in normalized coordinates (in the range from 0 to 1) and
map the viewing-coordinate description of the scene to normalized coordinates.
At the final step all parts of the picture that lie outside the viewport are clipped, and the contents of the
viewport are transferred to device coordinates. By changing the position of the viewport, we can view
objects at different positions on the display area of an output device.
A point at position (xw,yw) in a designated window is mapped to viewport coordinates (xv,yv) so that
relative positions in the two areas are the same. The figure illustrates the window to view port mapping. A
point at position (xw,yw) in the window is mapped into position (xv,yv) in the associated view port. To
maintain the same relative placement in view port as in window The conversion is performed with the
following sequence of transformations.
1. Perform a scaling transformation using point position of (xw min, yw min) that scales the window area
to the size of view port.
2. Translate the scaled window area to the position of view port. Relative proportions of objects are
maintained if scaling factor are the same(Sx=Sy).
Otherwise world objects will be stretched or contracted in either the x or y direction when displayed
on output device. For normalized coordinates, object descriptions are mapped to various display devices.
Any number of output devices can be open in particular application and another window view port
transformation can be performed for each open output device. This mapping called the work station
transformation is accomplished by selecting a window area in normalized apace and a view port are in
coordinates of display device.
Mapping selected parts of a scene in normalized coordinate to different video monitors with work
station transformation.
Window to Viewport transformation
The window defined in world coordinates is first transformed into the normalized device coordinates. The
normalized window is then transformed into the viewport coordinate. The window to viewport coordinate
transformation is known as workstation transformation. It is achieved by the following steps
1. The object together with its window is translated until the lower left corner of the window is at the orgin.
2. Object and window are scaled until the window has the dimensions of the viewport
The relation of the window and viewport display is expressed as XV-XVmin XW-XWmin
-------------- = ----------------
XVmax-XVmin XWmax-XWmin
YV-Yvmin YW-YWmin
-------------- = ----------------
YVmax-YVmin YWmax-YWmin
XV=XVmin + (XW-XWwmin)Sx
YV=YVmin + (YW-YWmin)Sy
XVmax-XVmin
Sx= --------------------
XWmax-Xwmin
YVmax-YVmin
Sy= --------------------
YWmax-YWmin
2D Clipping
The procedure that identifies the portion of a picture that are either inside or outside of a specified regin of
space is referred to as clipping. The regin against which an object is to be clipped is called a clip window or
clipping window.
The clipping algorithm determines which points, lines or portions of lines lie within the clipping window.
These points, lines or portions of lines are retained for display. All other are discarded. Possible clipping are
1. Point clipping
2. Line clipping
3. Area clipping
4. Curve Clipping
5. Text Clipping
Point Clipping:
The points are said to be interior to the clipping if XWmin <= X <=XW max
The equal sign indicates that points on the window boundary are included within the window.
Line Clipping:
- The lines are said to be interior to the clipping window, if the two end points of the lines are interior to
the window.
- If the lines are completely right of, completely to the left of, completely above, or completely below the
window, then it is discarded.
- Both end points of the line are exterior to the window, then the line is partially inside and partially
outside the window.The lines which across one or more clipping boundaries requires calculation of multiple
intersection points to decide the visible portion of them.To minimize the intersection calculation and
increase the efficiency of the clipping algorithm, initially completely visible and invisible lines are
identified and then intersection points are calculated for remaining lines.
It is developed by Dan Cohen and Ivan Sutharland. To speed up the processing this algorithm performs
initial tests that reduces the number of intersections that must be calculated.
both endpoints of the same side of clip rectangle 3. both endpoints outside clip rectangle
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
-------------------------
-------------------------
2. lines that cannot be identified as completely inside or outside are checked for the intersection with two
boundaries.
3. break the line segment into 2 line segments at the crossed edge
4. forget about the new line segment lying completely outside the clip rectangle
5. draw the line segment which lies within the boundary regin.
Point Clipping
Clipping a point from a given window is very easy. Consider the following figure, where the rectangle
indicates the window. Point clipping tells us whether the given point X,YX,Y is within the given window
or not; and decides whether we will use the minimum and maximum coordinates of the window.
The X-coordinate of the given point is inside the window, if X lies in between Wx1 ≤ X ≤ Wx2. Same
way, Y coordinate of the given point is inside the window, if Y lies in between Wy1 ≤ Y ≤ Wy2.
Line Clipping
The concept of line clipping is same as point clipping. In line clipping, we will cut the portion of line
which is outside of window and keep only the portion that is inside the window.
Cohen-Sutherland Line Clippings
This algorithm uses the clipping window as shown in the following figure. The minimum coordinate for
the clipping region is (XWmin,YWmin)(XWmin,YWmin) and the maximum coordinate for the clipping
region is (XWmax,YWmax)(XWmax,YWmax).
We will use 4-bits to divide the entire region. These 4 bits represent the Top, Bottom, Right, and Left of
the region as shown in the following figure. Here, the TOP and LEFT bit is set to 1 because it is the TOP-
LEFT corner.
While processing an edge of a polygon with clipping window, an intersection point is found if edge is not
completely inside clipping window and the a partial edge from the intersection point to the outside edge is
clipped. The following figures show left, right, top and bottom edge clippings −
Text Clipping
Various techniques are used to provide text clipping in a computer graphics. It depends on the methods
used to generate characters and the requirements of a particular application. There are three methods for
text clipping which are listed below −
All or none string clipping
All or none character clipping
Text clipping
The following figure shows all or none string clipping −
In all or none string clipping method, either we keep the entire string or we reject entire string based on the
clipping window. As shown in the above figure, STRING2 is entirely inside the clipping window so we
keep it and STRING1 being only partially inside the window, we reject.
The following figure shows all or none character clipping −
This clipping method is based on characters rather than entire string. In this method if the string is entirely
inside the clipping window, then we keep it. If it is partially outside the window, then −
You reject only the portion of the string being outside
If the character is on the boundary of the clipping window, then we discard that entire character and
keep the rest string.
The following figure shows text clipping −
This clipping method is based on characters rather than the entire string. In this method if the string is
entirely inside the clipping window, then we keep it. If it is partially outside the window, then
You reject only the portion of string being outside.
If the character is on the boundary of the clipping window, then we discard only that portion of
character that is outside of the clipping window.