0% found this document useful (0 votes)
2 views23 pages

CG Notes Unit - 4

The document provides study material for B.C.A Vth Semester on Computer Graphics, covering essential concepts such as 3D transformations (translation, rotation, scaling, reflection, and shearing) and their mathematical representations. It also discusses viewing and clipping techniques, including windowing, viewport mapping, and line clipping algorithms like Cohen Sutherland. The material emphasizes the importance of transformations and clipping in rendering graphics accurately on display devices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views23 pages

CG Notes Unit - 4

The document provides study material for B.C.A Vth Semester on Computer Graphics, covering essential concepts such as 3D transformations (translation, rotation, scaling, reflection, and shearing) and their mathematical representations. It also discusses viewing and clipping techniques, including windowing, viewport mapping, and line clipping algorithms like Cohen Sutherland. The material emphasizes the importance of transformations and clipping in rendering graphics accurately on display devices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

STUDY MATERIAL FOR

B.C.A Vth SEM.


COMPUTER GRAPHICS

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.

 3D Transformations take place in a three dimensional plane.


 3D Transformations are important and a bit more complex than 2D Transformations.
 Transformations are helpful in changing the position, size, orientation, shape etc of the
object.

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

In this article, we will discuss about 3D Translation in Computer Graphics.


3D Translation in Computer Graphics:
In Computer graphics, 3D Translation is a process of moving an object from one
position to another in a three dimensional plane.

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)

Given a Translation vector (Tx, Ty, Tz)-


 Tx defines the distance the Xold coordinate has to be moved.
 Ty defines the distance the Yold coordinate has to be moved.
 Tz defines the distance the Zold coordinate has to be moved.

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)

In Matrix form, the above translation equations may be represented as-

Page 48 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS

3D Rotation in Computer Graphics:


In Computer graphics, 3D Rotation is a process of rotating an object with respect to an
angle in a three dimensional plane.
Consider a point object O has to be rotated from one angle to another in a 3D plane.

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)

In 3 dimensions, there are 3 possible types of rotation:


 X-axis Rotation
 Y-axis Rotation
 Z-axis Rotation

For X-Axis Rotation:


This rotation is achieved by using the following rotation equations-
 Xnew = Xold
 Ynew = Yold x cosθ – Zold x sinθ
 Znew = Yold x sinθ + Zold x cosθ

In Matrix form, the above rotation equations may be represented as,

For Y-Axis Rotation:


This rotation is achieved by using the following rotation equations-
 Xnew = Zold x sinθ + Xold x cosθ 

Page 49 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS

 Ynew = Yold
 Znew = Yold x cosθ – Xold x sinθ

In Matrix form, the above rotation equations may be represented as-

For Z-Axis Rotation:


This rotation is achieved by using the following rotation equations-
 Xnew = Xold x cosθ – Yold x sinθ
 Ynew = Xold x sinθ + Yold x cosθ
 Znew = Zold

In Matrix form, the above rotation equations may be represented as-

3D Scaling in Computer Graphics:


In computer graphics, scaling is a process of modifying or altering the size of objects.
 Scaling may be used to increase or reduce the size of object.
 Scaling subjects the coordinate points of the original object to change.
 Scaling factor determines whether the object size is to be increased or reduced.
 If scaling factor > 1, then the object size is increased.
 If scaling factor < 1, then the object size is reduced.

Consider a point object O has to be scaled in a 3D plane. Let:


 Initial coordinates of the object O = (Xold, Yold,Zold)
 Scaling factor for X-axis = Sx
 Scaling factor for Y-axis = Sy
 Scaling factor for Z-axis = Sz

Page 50 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS

 New coordinates of the object O after scaling = (Xnew, Ynew, Znew)

This scaling is achieved by using the following scaling equations-


 Xnew = Xold x Sx
 Ynew = Yold x Sy
 Znew = Zold x Sz

In Matrix form, the above scaling equations may be represented as-

3D Reflection in Computer Graphics-


 Reflection is a kind of rotation where the angle of rotation is 180 degree.
 The reflected object is always formed on the other side of mirror.
 The size of reflected object is same as the size of original object.

Consider a point object O has to be reflected in a 3D plane.


Let,
 Initial coordinates of the object O = (Xold, Yold, Zold)
 New coordinates of the reflected object O after reflection = (Xnew, Ynew,Znew)

In 3 dimensions, there are 3 possible types of reflection:

 Reflection relative to XY plane


 Reflection relative to YZ plane
 Reflection relative to XZ plane

Reflection Relative to XY Plane:


This reflection is achieved by using the following reflection equations:
 Xnew = Xold
 Ynew = Yold
 Znew = -Zold

Page 51 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS

In Matrix form, the above reflection equations may be represented as-

Reflection Relative to YZ Plane:


This reflection is achieved by using the following reflection equations-
 Xnew = -Xold
 Ynew = Yold
 Znew = Zold

In Matrix form, the above reflection equations may be represented as-

Reflection Relative to XZ Plane:


This reflection is achieved by using the following reflection equations-
 Xnew = Xold
 Ynew = -Yold
 Znew = Zold

In Matrix form, the above reflection equations may be represented as:

Page 52 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS

3D Shearing in Computer Graphics:


In Computer graphics,
3D Shearing is an ideal technique to change the shape of an existing object in a three
dimensional plane

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

Consider a point object O has to be sheared in a 3D plane. Let:


 Initial coordinates of the object O = (Xold, Yold, Zold)
 Shearing parameter towards X direction = Shx
 Shearing parameter towards Y direction = Shy
 Shearing parameter towards Z direction = Shz
 New coordinates of the object O after shearing = (Xnew, Ynew, Znew)

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

In Matrix form, the above shearing equations may be represented as:

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

In Matrix form, the above shearing equations may be represented as-

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

In Matrix form, the above shearing equations may be represented as-

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.

Windows and viewports


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 dimensional viewing transformation is referred to as window
to view port transformation of windowing transformation.

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.

Object descriptions are then transferred to normalized device coordinates:


We do this thing using a transformation that maintains the same relative placement of
an object in normalized space as they had in viewing coordinates.

If a coordinate position is at the center of the viewing window:


It will display at the center of the viewport.Fig shows the window to viewport mapping.
A point at position (xw, yw) in window mapped into position (xv,yv) in the associated viewport.

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

Matrix Representation of the above three steps of Transformation:

Step1:Translate window to origin 1


Tx=-Xwmin Ty=-Ywmin

Step2:Scaling of the window to match its size to the viewport


Sx=(Xymax-Xvmin)/(Xwmax-Xwmin)
Sy=(Yvmax-Yvmin)/(Ywmax-Ywmin)

Step3:Again translate viewport to its correct position on screen.


Tx=Xvmin
Ty=Yvmin
Above three steps can be represented in matrix form:
VT=T * S * T1
T = Translate window to the origin
S=Scaling of the window to viewport size
T1=Translating viewport on screen.

Viewing Transformation= T * S * T1

Page 58 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS

Advantage of Viewing Transformation:


We can display picture at device or display system according to our need and choice.
Note:
 World coordinate system is selected suits according to the application program. 
 Screen coordinate system is chosen according to the need of design.
 Viewing transformation is selected as a bridge between the world and screen
coordinate

Line Clipping:
It is performed by using the line clipping algorithm.

The line clipping algorithms are:


1. Cohen Sutherland Line Clipping Algorithm
2. Midpoint Subdivision Line Clipping Algorithm
3. Liang-Barsky Line Clipping Algorithm

Cohen Sutherland Line Clipping Algorithm:


In the algorithm, first of all, it is detected whether line lies inside the screen or it is
outside the screen.

All lines come under any one of the following categories:


1. Visible
2. Not Visible
3. Clipping Case

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.

xmin,xmax are coordinates of the window.


ymin,ymax are also coordinates of the window.
x1>xmax
x2>xmax
y1>ymax
y2>ymax
x1<xmin
x2<xmin
y1<ymin
y2<ymin

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.

Following figure show lines of various types

 Line AB is the visible case


 Line OP is an invisible case
 Line PQ is an invisible line
 Line IJ are clipping candidates

Page 60 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS

 Line MN are clipping candidate


 Line CD are clipping candidate

Advantage of Cohen Sutherland Line Clipping:


1. It calculates end-points very quickly and rejects and accepts lines quickly.
2. It can clip pictures much large than screen size.

Algorithm of Cohen Sutherland Line Clipping:


Step1:Calculate positions of both endpoints of the line

Step2:Perform OR operation on both of these end-points

Step3:If the OR operation gives 0000


Thenline is considered to be visible
Else
Perform AND operation on both endpoint
If And ≠ 0000
Then the line is invisible
Else
And=0000
Line is considered the clipped case.

Step4:If a line is clipped case, find an intersection with boundaries of the window
m=(y2-y1 )(x2-x1)

a) If bit 1 is "1" line intersects with left boundary of rectangle window


y3=y1+m(x-X1)
where X = Xwmin
where Xwminis the minimum value of X co-ordinate of window
b) If bit 2 is "1" line intersect with right boundary
y3=y1+m(X-X1)
where X = Xwmax
where X more is maximum value of X co-ordinate of the window
c) If bit 3 is "1" line intersects with bottom boundary
X3=X1+(y-y1)/m
where y = ywmin
ywmin is the minimum value of Y co-ordinate of the window
d) If bit 4 is "1" line intersects with the top boundary
X3=X1+(y-y1)/m
where y = ywmax
ywmax is the maximum value of Y co-ordinate of the window

Mid Point Subdivision Line Clipping Algorithm:

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.

x5lie on point of intersection of boundary of window.

Advantage of midpoint subdivision Line Clipping:


It is suitable for machines in which multiplication and division operation is not possible.
Because it can be performed by introducing clipping divides in hardware.

Algorithm of midpoint subdivision Line Clipping:


Step1: Calculate the position of both endpoints of the line
Step2: Perform OR operation on both of these endpoints
Step3: If the OR operation gives 0000
then
Line is guaranteed to be visible
else
Perform AND operation on both endpoints.
If AND ≠ 0000
then the line is invisible
else
AND=6000
then the line is clipped case.

Step4: For the line to be clipped. Find midpoint


Xm=(x1+x2)/2
Ym=(y1+y2)/2
Xmis midpoint of X coordinate.
Ymis midpoint of Y coordinate.

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.

Step7: Stop algorithm.

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:

Step1: Fix point A (-4, 2)

Step2: Find b"=mid of b'and b

So (-1, 5) is better than (2, 4)

Find b"&bb"(-1, 5) b (-1, 7)

Page 63 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS

So B""to B length of line will be clipped from upper side

Now considered left-hand side portion

A and B""are now endpoints

Find mid of A and B""

A (-4, 2) B ""(-1, 6)

Page 64 of 82
STUDY MATERIAL FOR
B.C.A Vth SEM.
COMPUTER GRAPHICS

Sutherland-Hodgeman Polygon Clipping Algorithm:-


A polygon can be clipped by processing its boundary as a whole against each window
edge. This is achieved by processing all polygon vertices against each clip rectangle boundary in
turn. beginning with the original set of polygon vertices, we could first clip the polygon against
the left rectangle boundary to produce a new sequence of vertices. The new set of vertices
could then be successively passed to a right boundary clipper, a top boundary clipper and a
bottom boundary clipper, as shown in figure (l). At each step a new set of polygon vertices is
generated and passed to the next window boundary clipper. This is the fundamental idea used
in the Sutherland - Hodgeman algorithm.

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.

1. Determining the visibility of a point or vertex (lnside - Outside test) and


2. Determining the intersection of the polygon edge and the clipping plane.

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

Sutherland-Hodgeman Polygon Clipping Algorithm:-

1. Read coordinates of all vertices of the Polygon.


2. Read coordinates of the dipping window
3. Consider the left edge of the window
4. Compare the vertices of each edge of the polygon, individually with the clipping plane.
5. Save the resulting intersections and vertices in the new list of vertices according to four
possible relationships between the edge and the clipping boundary.
6. Repeat the steps 4 and 5 for remaining edges or the clipping window. Each time the
resultant list of vertices is successively passed to process the next edge of the clipping
window.
7. Stop.

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.

Hidden Surface Elimination


1. One of the most challenging problems in computer graphics is the removal of hidden
parts from images of solid objects.
2. In real life, the opaque material of these objects obstructs the light rays from hidden
parts and prevents us from seeing them.
3. In the computer generation, no such automatic elimination takes place when objects
are projected onto the screen coordinate system.
4. Instead, all parts of every object, including many parts that should be invisible are
displayed.

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.

Types of hidden surface detection algorithms:


1. Object space methods
2. Image space methods

Object space methods:


In this method, various parts of objects are compared. After comparison visible, invisible
or hardly visible surface is determined. These methods generally decide visible surface. In the
wireframe model, these are used to determine a visible line. So these algorithms are line based
instead of surface based. Method proceeds by determination of parts of an object whose view
is obstructed by other object and draws these parts in the same color.

Image space methods:


Here positions of various pixels are determined. It is used to locate the visible surface
instead of a visible line. Each point is detected for its visibility. If a point is visible, then the pixel
is on, otherwise off. So the object close to the viewer that is pierced by a projector through a
pixel is determined. That pixel is drawn is appropriate color.

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

You might also like