CG Unit 2 Ashish
CG Unit 2 Ashish
SYLLABUS
(c)
10 | P a g e Ashish Tripathi
11 | P a g e Ashish Tripathi
Homogeneous Coordinate System
To perform a sequence of transformation such as translation followed by rotation
and scaling, we need to follow a sequential process:
1. Translate the coordinates,
2. Rotate the translated coordinates, and then
3. Scale the rotated coordinates to complete the composite transformation.
To shorten this process, we have to use 3×3 transformation matrix instead of 2×2
transformation matrix. To convert a 2×2 matrix to 3×3 matrix, we have to add an
extra dummy coordinate W. In this way, we can represent the point by 3
numbers instead of 2 numbers, which is called Homogenous Coordinate
system. In this system, we can represent all the transformation equations in
matrix multiplication. Any Cartesian point P(X, Y) can be converted to
homogenous coordinates by P’ (Xh, Yh, h).
12 | P a g e Ashish Tripathi
2-D VIEWING
13 | P a g e Ashish Tripathi
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 O to I) and map the viewing-coordinate description of the scene
to normalized coordinates. At the final step, the parts of the picture that he
outside the viewport are clipped, and the contents of the viewport are transferred
to device coordinates.
14 | P a g e Ashish Tripathi
A Window is a rectangular region in the world coordinate system. This is the
coordinate system used to locate an object in the natural world. The world
coordinate system does not depend on a display device, so the units of measure
can be positive, negative or decimal numbers.
A Viewport is the section of the screen where the images encompassed by the
window on the world coordinate system will be drawn. A coordinate
transformation is required to display the image, encompassed by the window, in
the viewport. The viewport uses the screen coordinate system so this
transformation is from the world coordinate system to the screen coordinate
system.
The final transformation matrix can be determined by composing the matrices
for the following transformations:
1. Translate the world-coordinate window to the origin.
2. Rotate the window to match the orientation of the screen window (i.e.
viewport).
3. Scale the window to match the size of the viewport.
4. Translate the window to the screen
When a window is "placed" on the world, only certain objects and parts of objects
can be seen. Points and lines which are outside the window are "cut off" from
view. This process of "cutting off" parts of the image of the world is called
Clipping.
In clipping, we examine each line to determine whether or not it is completely
inside the window, completely outside the window, or crosses a window
boundary. If inside the window, the line is displayed. If outside the window, the
lines and points are not displayed. If a line crosses the boundary, we must
determine the point of intersection and display only the part which lies inside the
window.
A window is specified by four world coordinates: wxmin, wxmax, wymin,and wymax
.Similarly, a viewport is described by four normalized device coordinates:
vxmin,vxmax,vymin, and vymax. The objective of window – to – viewport mapping is to
convert the world coordinates (wx, wy) of an arbitrary point to its corresponding
normalized device coordinates (vx,vy). In order to maintain the same relative
placement of the point in the viewport as in the window, we require:
15 | P a g e Ashish Tripathi
Cohen-
Point Clipping
Point clipping is essentially the evaluation of the following inequalities:
xmin ≤ x ≤ xmax and ymin ≤ y ≤ ymax
Where xmin, xmax, ymin and ymax define the clipping window. A point (x,y) is
considered inside the window when the inequalities all evaluate to true.
16 | P a g e Ashish Tripathi
Line Clipping
Lines that do not intersect the clipping window are either completely inside the
window or completely outside the window. On the other hand, a line that
intersects the clipping window is divided by the intersection point(s) into
segments that are either inside or outside the window.
17 | P a g e Ashish Tripathi
Bit 1 ≡ endpoint is above the window = sign (y – ymax)
Bit 2 ≡ endpoint is below the window = sign (ymin-y)
Bit 3 ≡ endpoint is to the right of the window = sign (x–xmax)
Bit 4 ≡ endpoint is to the left of the window = sign (xmin –x)
We use the convention that sign (a) = 1, if ‘a’ is positive, 0 otherwise. Of course, a
point with code 0000 is inside the window.
2. The line is visible if both region codes are 0000, and not visible if the bitwise
logical AND of the codes is not 0000, and a candidate for clipping if the bitwise
logical AND of the region codes is 0000.
For a line in category 3 we proceed to find the intersection point of the line with
one of the boundaries of the clipping window, or to be exact, with the infinite
extension of one of the boundaries. We choose an endpoint of the line, say (x1,
y1), that is outside the window, i.e., whose region code is not 0000. We then
select an extended boundary line by observing that those boundary lines that are
candidates for intersection are of ones for which the chosen endpoint must be
“pushed across” so as to change a “1” in its code to a “0” .
This means:
If bit 1 is 1, intersect with line y = ymax.
If bit 2 is 1, intersect with line y = ymin.
If bit 3 is 1, intersect with line x = xmax.
18 | P a g e Ashish Tripathi
If bit 4 is 1, intersect with line x = xmin.
Consider line CD. If endpoint C is chosen, then the bottom boundary line y=ymin
is selected for computing intersection. On the other hand, if endpoint D is
chosen, then either the top boundary line y=ymax or the right boundary line x =
xmax is used.
The coordinates of the intersection point are
Now we replace endpoint (x1, y1) with the intersection point (x1, yi) effectively
eliminating the portion of the original line that is on the outside of the selected
window boundary. The new endpoint is then assigned an updated region code
and the clipped line re-categorized and handled in the same way.
19 | P a g e Ashish Tripathi
20 | P a g e Ashish Tripathi
Area Clipping
An algorithm that clips a polygon is called an area clipping. Each edge of the
polygon must be tested against each edge of the clip rectangle; new edges must
be added, and existing edges must be discarded, retained, or divided.
21 | P a g e Ashish Tripathi
END OF UNIT II
22 | P a g e Ashish Tripathi