CG Notes Unit - 4
CG Notes Unit - 4
Example x’ = x
Y’ = shy (x – x ref) + y
Shy = ½ and x ref = -1
3D Transformation:
In Computer graphics, Transformation is a process of modifying and re-positioning the
existing graphics.
Transformation Techniques:
In computer graphics, various transformation techniques are
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shear
Page 47 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Consider a point object O has to be moved from one position to another in a 3D plane.
Let
Initial coordinates of the object O = (Xold, Yold, Zold)
New coordinates of the object O after translation = (Xnew, Ynew , Zold)
Translation vector or Shift vector = (Tx, Ty, Tz)
This translation is achieved by adding the translation coordinates to the old coordinates of the
object as-
Xnew = Xold + Tx (This denotes translation towards X axis)
Ynew = Yold + Ty (This denotes translation towards Y axis)
Znew = Zold + Tz (This denotes translation towards Z axis)
Page 48 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Let-
Initial coordinates of the object O = (Xold, Yold, Zold)
Initial angle of the object O with respect to origin = Φ
Rotation angle = θ
New co-ordinates of the object O after rotation = (Xnew, Ynew, Znew)
Page 49 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Ynew = Yold
Znew = Yold x cosθ – Xold x sinθ
Page 50 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Page 51 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Page 52 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
In a three dimensional plane, the object size can be changed along X direction, Y
direction as well as Z direction.So, there are three versions of shearing:
1. Shearing in X direction
2. Shearing in Y direction
3. Shearing in Z direction
Shearing in X Axis-
Shearing in X axis is achieved by using the following shearing equations-
Xnew = Xold
Ynew = Yold + Shy x Xold
Znew = Zold + Shz x Xold
Page 53 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Shearing in Y Axis-
Shearing in Y axis is achieved by using the following shearing equations:
Xnew = Xold + Shx x Yold
Ynew = Yold
Znew = Zold + Shz x Yold
Shearing in Z Axis-
Shearing in Z axis is achieved by using the following shearing equations-
Xnew = Xold + Shx x Zold
Ynew = Yold + Shy x Zold
Znew = Zold
Page 54 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Page 55 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
UNIT – IV
CLIPPING
Viewing and clipping
The process of selecting and viewing the picture with different views is called windowing
and a process which divides each element of the picture into its visible and invisible portions,
allowing the invisible portion to be discarded is calledclipping.
Viewing Transformation
Once object description has been transmitted to the viewing reference frame, we
choose the window extends in viewing coordinates and selects the viewport limits in
normalized coordinates.
Page 56 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
In order to maintain the same relative placement of the point in the viewport as in the window,
we require:
Solving these impressions for the viewport position (xv, yv), we have
xv=xvmin+(xw-xwmin)sx
yv=yvmin+(yw-ywmin)sy .......... equation 2
Where scaling factors are
Equation (1) and Equation (2) can also be derived with a set of transformation that converts the
window or world coordinate area into the viewport or screen coordinate area. This
conversation is performed with the following sequence of transformations:
1. Perform a scaling transformation using a fixed point position (xwmin,ywmin) that scales
the window area to the size of the viewport.
2. Translate the scaled window area to the position of the viewport. Relative proportions
of objects are maintained if the scaling factors are the same (sx=sy).
From normalized coordinates, object descriptions are mapped to the various display
devices.Any number of output devices can we open in a particular app, and three windows to
viewport transformation can be performed for each open output device.This mapping called
workstation transformation (It is accomplished by selecting a window area in normalized space
and a viewport area in the coordinates of the display device).As in fig, workstation
transformation to partition a view so that different parts of normalized space can be displayed
on various output devices).
Page 57 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Viewing Transformation= T * S * T1
Page 58 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Line Clipping:
It is performed by using the line clipping algorithm.
1. Visible:
If a line lies within the window, i.e., both endpoints of the line lies within the window. A
line is visible and will be displayed as it is.
2. Not Visible:
If a line lies outside the window it will be invisible and rejected. Such lines will not
display. If any one of the following inequalities is satisfied, then the line is considered invisible.
Let A (x1,y2) and B (x2,y2) are endpoints of line.
3. Clipping Case:
Page 59 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
If the line is neither visible case nor invisible case. It is considered to be clipped case.
First of all, the category of a line is found based on nine regions given below. All nine regions
are assigned codes. Each code is of 4 bits. If both endpoints of the line have end bits zero, then
the line is considered to be visible.
The centre area is having the code, 0000, i.e., region 5 is considered a rectangle window.
Page 60 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Step4:If a line is clipped case, find an intersection with boundaries of the window
m=(y2-y1 )(x2-x1)
Page 61 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
It is used for clipping line. The line is divided in two parts. Mid points of line is obtained
by dividing it in two short segments. Again division is done, by finding midpoint. This process is
continued until line of visible and invisible category is obtained. Let (xi,yi) are midpoint.
Step5: Check each midpoint, whether it nearest to the boundary of a window or not.
Page 62 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Step6: If the line is totally visible or totally rejected not found then repeat step 1 to 5.
Example: Window size is (-3, 1) to (2, 6). A line AB is given having co-ordinates of A (-4, 2) and B
(-1, 7). Does this line visible. Find the visible portion of the line using midpoint subdivision?
Solution:
Page 63 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
A (-4, 2) B ""(-1, 6)
Page 64 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
The output of the algorithm is a list of polygon vertices all of which are on the visible
side of a clipping plane. Such each edge of the polygon is individually compared with the
clipping plane. This is achieved by processing two vertices of each edge of the polygon around
the clipping boundary or plane. This results in four possible relationships between the
edge and the clipping boundary or Plane. (See Fig. m).
Page 65 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
1. If the first vertex of the edge is outside the window boundary and the second vertex of
the edge is inside then the intersection point of the polygon edge with the window
boundary and the second vertex are added to the output vertex list (See Fig. m (a)).
2. If both vertices of the edge are inside the window boundary, only the second vertex is
added to the output vertex list. (See Fig. m (b)).
3. If the first vertex of the edge is inside the window boundary and the second vertex of
the edge is outside, only the edge intersection with the window boundary is added to
the output vertex list. (See Fig. m (c)).
4. If both vertices of the edge are outside the window boundary, nothing is added to the
output list. (See Fig. m (d)).
Once all vertices are processed for one clip window boundary, the output list of vertices
is clipped against the next window boundary. Going through above four cases we can realize
that there are two key processes in this algorithm.
Page 66 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
One way of determining the visibility of a point or vertex is described here. Consider
that two points A and B define the window boundary and point under consideration is V, then
these three points define a plane. Two vectors which lie in that plane are AB and AV. If this
plane is considered in the xy plane, then the vector cross product AV x AB has only a
component given by
The sign of the z component decides the position of Point V with respect to window
boundary.
If z is:
Positive - Point is on the right side of the window boundary.
Zero - Point is on the window boundary.
Negative - Point is on the left side of the window boundary.
Page 67 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
Example:
For a polygon and clipping window shown in figure below give the list of vertices after each
boundary clipping.
Solution:
Original polygon vertices are V1, V2, V3, V4, and V5. After clipping each boundary the
new vertices are as shown in figure above.
Page 68 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS
5. To remove these parts to create a more realistic image, we must apply a hidden line or
hidden surface algorithm to set of objects.
6. The algorithm operates on different kinds of scene models, generate various forms of
output or cater to images of different complexities.
7. All use some form of geometric sorting to distinguish visible parts of objects from those
that are hidden.
8. Just as alphabetical sorting is used to differentiate words near the beginning of the
alphabet from those near the ends.
9. Geometric sorting locates objects that lie near the observer and are therefore visible.
10. Hidden line and Hidden surface algorithms capitalize on various forms of coherence to
reduce the computing required to generate an image.
11. Different types of coherence are related to different forms of order or regularity in the
image.
12. Scan line coherence arises because the display of a scan line in a raster image is usually
very similar to the display of the preceding scan line.
13. Frame coherence in a sequence of images designed to show motion recognizes that
successive frames are very similar.
14. Object coherence results from relationships between different objects or between
separate parts of the same objects.
15. A hidden surface algorithm is generally designed to exploit one or more of these
coherence properties to increase efficiency.
16. Hidden surface algorithm bears a strong resemblance to two-dimensional scan
conversions.
These methods are also called a Visible Surface Determination. The implementation of
these methods on a computer requires a lot of processing time and processing power of the
computer.
The image space method requires more computations. Each object is defined clearly.
Visibility of each object surface is also determined.
Page 69 of 82