Computer Graphics1
Computer Graphics1
Board of Studies
___________________________________________________________________________________________
Subject Expert Panel
___________________________________________________________________________________________
Content Review Panel
___________________________________________________________________________________________
Copyright ©
Printed by
Universal Training Solutions Private Limited
Address
05th Floor, I-Space,
Bavdhan, Pune 411021.
All rights reserved. This book or any portion thereof may not, in any form or by any means including electronic
or mechanical or photocopying or recording, be reproduced or distributed or transmitted or stored in a retrieval
system or be broadcasted or transmitted.
___________________________________________________________________________________________
Index
I. Content....................................................................... II
IV. Abbreviations.......................................................... X
Book at a Glance
I
Contents
Chapter I........................................................................................................................................................ 1
Introduction to Computer Graphics........................................................................................................... 1
Aim................................................................................................................................................................. 1
Objectives....................................................................................................................................................... 1
Learning outcome........................................................................................................................................... 1
1.1 Introduction............................................................................................................................................... 2
1.1.1 Advantages of Computer Graphics........................................................................................... 2
1.1.2 Applications of Computer Graphics......................................................................................... 2
1.1.3 Classification of Computer Graphics........................................................................................ 3
1.2 Lines.......................................................................................................................................................... 4
1.3 Line Segment............................................................................................................................................ 4
1.4 Vectors....................................................................................................................................................... 4
1.5 Pixels and Frame Buffers.......................................................................................................................... 5
1.6 Vector Generation..................................................................................................................................... 5
1.7 Vector Generation/Digital Differential Analyser (DDA) Algorithm......................................................... 6
1.7.1 ‘C’ Code for DDA Line Drawing Algorithm............................................................................ 7
1.7.2 Advantages of DDA Algorithm................................................................................................. 8
1.7.3 Disadvantages of DDA Algorithm............................................................................................ 8
1.8 Bresenham’s Line Algorithm.................................................................................................................... 8
1.8.1 ‘C’ Code for Bresenham’s Line Drawing Algorithm................................................................ 9
1.9 Circle and Ellipse Drawing Algorithms.................................................................................................. 10
1.9.1 Midpoint Circle Drawing Algorithm...................................................................................... 10
1.9.2 Ellipse Drawing Algorithm......................................................................................................11
1.10 Display of Frame Buffer....................................................................................................................... 14
Summary...................................................................................................................................................... 15
References.................................................................................................................................................... 15
Recommended Reading.............................................................................................................................. 15
Self Assessment............................................................................................................................................ 16
Chapter II.................................................................................................................................................... 18
Graphics Primitives.................................................................................................................................... 18
Aim............................................................................................................................................................... 18
Objectives..................................................................................................................................................... 18
Learning outcome......................................................................................................................................... 18
2.1 Display Devices...................................................................................................................................... 19
2.1.1 Cathode Ray Tubes (CRT)...................................................................................................... 19
2.1.2 Vector Scan/Random Scan Display........................................................................................ 20
2.1.3 Raster Scan Display................................................................................................................ 21
2.1.4 Important Characteristics of Video Display Devices.............................................................. 22
2.2 Interactive Devices.................................................................................................................................. 23
2.2.1 The Keyboard......................................................................................................................... 23
2.2.2 Mouse...................................................................................................................................... 23
2.2.3 Trackball................................................................................................................................. 23
2.2.4 Joystick................................................................................................................................... 23
2.2.5 Data Glove.............................................................................................................................. 23
2.2.6 Light Pen................................................................................................................................. 23
2.3 Data Generating Devices........................................................................................................................ 23
2.4 Primitive Operations............................................................................................................................... 24
2.4.1 Syntax of Graphics Primitives................................................................................................ 24
2.4.1.1 Lines and Polylines.................................................................................................. 24
2.4.1.2 Markers and Polymarkers........................................................................................ 25
2.4.1.3 Polygons and Rectangles.......................................................................................... 25
2.4.2 Attributes................................................................................................................................. 26
II
2.4.3 Filled Primitives and Their Attributes.................................................................................... 27
2.5 Display File Structure............................................................................................................................. 28
2.6 Display File Interpreter........................................................................................................................... 29
2.7 Normalised Device Coordinates............................................................................................................. 30
2.8 Display Processor.................................................................................................................................... 30
Summary...................................................................................................................................................... 31
References.................................................................................................................................................... 31
Recommended Reading.............................................................................................................................. 31
Self Assessment............................................................................................................................................ 32
Chapter III................................................................................................................................................... 34
Polygons....................................................................................................................................................... 34
Aim............................................................................................................................................................... 34
Objectives..................................................................................................................................................... 34
Learning outcome......................................................................................................................................... 34
3.1 Introduction............................................................................................................................................. 35
3.2 Types of Polygons................................................................................................................................... 35
3.3 Representation of Polygons.................................................................................................................... 36
3.4 Entering Polygons................................................................................................................................... 36
3.5 Polygon Filling....................................................................................................................................... 37
3.5.1 Seed Fill.................................................................................................................................. 37
3.5.1.1 Boundary Fill Algorithm / Edge Fill Algorithm....................................................... 37
3.5.1.2 ‘C’ Code for Boundary Algorithm (8-Connected Region)....................................... 38
3.5.1.3 Flood Fill Algorithm................................................................................................ 39
3.5.2 Scan Line Algorithm............................................................................................................... 39
3.5.2.1 ‘C’ Code for Scan Line Algorithm for Filling Polygon........................................... 40
3.5.2.2 Features of Scan Line Algorithm............................................................................. 46
3.6 Filling with Patterns................................................................................................................................ 46
3.7 Scan Conversion..................................................................................................................................... 46
Summary...................................................................................................................................................... 47
References.................................................................................................................................................... 47
Recommended Reading.............................................................................................................................. 47
Self Assessment............................................................................................................................................ 48
Chapter IV................................................................................................................................................... 50
2D Transformations ................................................................................................................................... 50
Aim............................................................................................................................................................... 50
Objectives..................................................................................................................................................... 50
Learning outcome......................................................................................................................................... 50
4.1 Matrices................................................................................................................................................... 51
4.1.1 Matrix Multiplication.............................................................................................................. 51
4.1.2 Identity Matrix........................................................................................................................ 52
4.2 Two Dimensional Transformations......................................................................................................... 52
4.2.1 Translation.............................................................................................................................. 52
4.2.2 Rotation................................................................................................................................... 53
4.2.3 Scaling.................................................................................................................................... 54
4.3 Homogeneous Coordinates..................................................................................................................... 55
4.3.1 Homogeneous Coordinates for Translation............................................................................ 56
4.3.2 Homogeneous Coordinates for Rotation................................................................................. 56
4.3.3 Homogeneous Coordinates for Scaling.................................................................................. 56
4.4 Composition of 2D Transformations...................................................................................................... 56
4.4.1 Rotation About an Arbitrary Point.......................................................................................... 56
Summary...................................................................................................................................................... 58
References.................................................................................................................................................... 58
Recommended Reading.............................................................................................................................. 58
Self Assessment............................................................................................................................................ 59
III
Chapter V..................................................................................................................................................... 61
Windowing and Clipping........................................................................................................................... 61
Aim............................................................................................................................................................... 61
Objectives..................................................................................................................................................... 61
Learning outcome......................................................................................................................................... 61
5.1 Introduction............................................................................................................................................. 62
5.2 Viewing Transformation......................................................................................................................... 62
5.2.1 Normalised Coordinates......................................................................................................... 63
5.3 Window to Viewport Coordinate Transformation................................................................................... 64
5.4 Workstation Transformation................................................................................................................... 64
5.5 Two Dimensional Viewing Functions..................................................................................................... 64
5.6 2D Clipping............................................................................................................................................. 65
5.6.1 Point Clipping......................................................................................................................... 65
5.6.2 Line Clipping.......................................................................................................................... 66
5.7 Cohen-Sutherland Subdivision Line Clipping Algorithm....................................................................... 66
5.7.1 ‘C’ Code for Sutherland and Cohen Subdivision Line Clipping Algorithm........................... 67
5.8 Polygon Clipping.................................................................................................................................... 70
5.9 Sutherland-Hodgeman Polygon Clipping Algorithm.............................................................................. 70
5.9.1 ‘C’ Code for Sutherland-Hodgeman Polygon Clipping Algorithm........................................ 70
Summary...................................................................................................................................................... 76
References.................................................................................................................................................... 76
Recommended Reading.............................................................................................................................. 76
Self Assessment............................................................................................................................................ 77
Chapter VI................................................................................................................................................... 79
3-D Transformations................................................................................................................................... 79
Aim............................................................................................................................................................... 79
Objectives..................................................................................................................................................... 79
Learning outcome......................................................................................................................................... 79
6.1 Introduction............................................................................................................................................. 80
6.2 3-D Geometry......................................................................................................................................... 80
6.3 3-D Primitive.......................................................................................................................................... 80
6.3.1 Algorithm 1: 3-D Absolute Move........................................................................................... 80
6.3.2 Algorithm 2: 3-D Relative Move............................................................................................ 81
6.3.3 Algorithm 3: 3-D Absolute Line Drawing Routine................................................................ 81
6.3.4 Algorithm 4: 3-D Relative Line Drawing Routine................................................................. 81
6.3.5 Algorithm 5: Absolute Polygon Drawing Routine.................................................................. 81
6.3.6 Algorithm 6: 3-D Relative Polygon Drawing Routine........................................................... 82
6.4 Techniques To Achieve Realism............................................................................................................. 82
6.4.1 Depth Cueing.......................................................................................................................... 82
6.4.2 Surface Rendering................................................................................................................... 83
6.4.3 Stereoscopic Views................................................................................................................. 83
6.4.4 Material Properties.................................................................................................................. 83
6.4.5 Shadows.................................................................................................................................. 83
6.5 Three Dimensional Transformations....................................................................................................... 83
6.5.1 Translation.............................................................................................................................. 83
6.5.2 Scaling.................................................................................................................................... 84
6.5.3 Rotation................................................................................................................................... 85
6.5.4 Reflection................................................................................................................................ 85
6.6 Three Dimensional Viewing................................................................................................................... 85
6.7 Projections............................................................................................................................................... 86
6.7.1 Parallel Projection................................................................................................................... 86
6.7.2 Perspective Projection............................................................................................................. 86
6.7.3 Types of Parallel Projections.................................................................................................. 87
6.7.3.1 Orthographic Projection........................................................................................... 87
IV
6.7.3.2 Oblique Projection................................................................................................... 87
6.7.4 Types of Perspective Projections............................................................................................ 88
Summary...................................................................................................................................................... 89
References.................................................................................................................................................... 89
Recommended Reading.............................................................................................................................. 89
Self Assessment............................................................................................................................................ 90
Chapter VII................................................................................................................................................. 92
Hidden Surfaces and Lines........................................................................................................................ 92
Aim............................................................................................................................................................... 92
Objectives..................................................................................................................................................... 92
Learning outcome......................................................................................................................................... 92
7.1 Introduction............................................................................................................................................. 93
7.1.1 Object-Space Method............................................................................................................. 93
7.1.2 Image-Space Method.............................................................................................................. 93
7.2 Z-Buffer Algorithm................................................................................................................................. 93
7.2.1 Advantages.............................................................................................................................. 94
7.2.2 Disadvantages......................................................................................................................... 94
7.3 Scan Line Algorithm............................................................................................................................... 94
7.4 Warnock’s Algorithm.............................................................................................................................. 94
7.4.1 Advantages.............................................................................................................................. 96
7.5 Hidden Line Methods............................................................................................................................. 96
7.6 Binary Space Partition Trees (BSP)........................................................................................................ 96
7.6.1 The Pseudo Code for Building a BSP Tree............................................................................. 97
7.6.2 The Pseudo Code for Displaying a BSP Tree......................................................................... 98
Summary...................................................................................................................................................... 99
References.................................................................................................................................................... 99
Recommended Reading.............................................................................................................................. 99
Self Assessment.......................................................................................................................................... 100
V
Chapter IX..................................................................................................................................................111
Curves, Fractals and Animation...............................................................................................................111
Aim..............................................................................................................................................................111
Objectives....................................................................................................................................................111
Learning outcome........................................................................................................................................111
9.1 Introduction............................................................................................................................................112
9.1.1 Curve Generation...................................................................................................................112
9.1.2 Problems in True-Curve Generation Approach.....................................................................112
9.2 Interpolation...........................................................................................................................................112
9.3 Spline Representation............................................................................................................................114
9.3.1 Spline Specifications..............................................................................................................114
9.4 Bezier Curves.........................................................................................................................................114
9.4.1 Properties of Bezier Curve.....................................................................................................115
9.5 B-Spline Curves.....................................................................................................................................115
9.5.1 Properties of B-Spline Curve.................................................................................................115
9.6 Fractals...................................................................................................................................................116
9.6.1 Classification of Fractals.......................................................................................................116
9.6.1.1 Self Similar Fractals................................................................................................116
9.6.1.2 Self Affine Fractals..................................................................................................116
9.6.1.3 Invariant Fractals.....................................................................................................116
9.7 Fractal Lines...........................................................................................................................................116
9.8 Fractal Surfaces......................................................................................................................................117
Summary.....................................................................................................................................................118
References...................................................................................................................................................118
Recommended Reading.............................................................................................................................118
Self Assessment...........................................................................................................................................119
VI
List of Figures
Fig. 1.1 Applications of computer graphics.................................................................................................... 3
Fig. 1.2 Classification of computer graphics.................................................................................................. 3
Fig. 1.3 Line segment...................................................................................................................................... 4
Fig. 1.4 Vectors............................................................................................................................................... 4
Fig. 1.5 Vector generations............................................................................................................................. 5
Fig. 1.6 Vector generations............................................................................................................................. 6
Fig. 1.7 Bresenham’s line algorithm............................................................................................................... 8
Fig. 1.8 Midpoint circle drawing algorithm.................................................................................................. 10
Fig. 1.9 Ellipse drawing algorithms.............................................................................................................. 12
Fig. 1.10 Frame buffer using eight 5-bit shift register.................................................................................. 14
Fig. 1.11 Frame buffer graphics system........................................................................................................ 14
Fig. 2.1 Cathode ray tube.............................................................................................................................. 19
Fig. 2.2 Vector scan CRT.............................................................................................................................. 20
Fig. 2.3 Architecture of a vector display....................................................................................................... 20
Fig. 2.4 Architecture of a raster display........................................................................................................ 21
Fig. 2.5 Raster scan CRT.............................................................................................................................. 21
Fig. 2.6 Screen Cartesian reference system.................................................................................................. 24
Fig. 2.7 Polyline drawing.............................................................................................................................. 25
Fig. 2.8 Polyline with markers...................................................................................................................... 25
Fig. 2.9 Polygon............................................................................................................................................ 26
Fig. 2.10 Rectangle....................................................................................................................................... 26
Fig. 2.11 Convex polygons........................................................................................................................... 27
Fig. 2.12 Concave polygons.......................................................................................................................... 27
Fig. 2.13 Vector refresh display system........................................................................................................ 29
Fig. 2.14 Display file and interpreter............................................................................................................ 29
Fig. 2.15 Raster scan system with a display processor................................................................................. 30
Fig. 3.1 Terminal point.................................................................................................................................. 35
Fig. 3.2 Convex polygon............................................................................................................................... 35
Fig. 3.3 Concave polygon............................................................................................................................. 35
Fig. 3.4 Representation of polygon............................................................................................................... 36
Fig. 3.5 Boundary defined regions................................................................................................................ 37
Fig. 3.6 Partial filling resulted using 4-connected algorithm........................................................................ 38
Fig. 3.7 Scan line.......................................................................................................................................... 40
Fig. 3.8 Intersection points along the scan line that intersect polygon vertices............................................ 40
Fig. 3.9 Filling pattern.................................................................................................................................. 46
Fig. 4.1 Translation....................................................................................................................................... 52
Fig. 4.2 Rotation of object about the origin.................................................................................................. 53
Fig. 4.3 Scaling............................................................................................................................................. 54
Fig. 4.4 Rotation about an arbitrary point..................................................................................................... 57
Fig. 5.1 Display images................................................................................................................................ 62
Fig. 5.2 Two dimensional viewing transformation pipeline......................................................................... 62
Fig. 5.3 Window and viewport...................................................................................................................... 63
Fig. 5.4 Picture defined in pixels.................................................................................................................. 63
Fig. 5.5 Four-bit codes for nine regions........................................................................................................ 66
Fig. 5.6 Polygon clipping done by line clipping algorithm.......................................................................... 70
Fig. 6.1 Depth cueing.................................................................................................................................... 82
Fig. 6.2 3-D translation................................................................................................................................. 84
Fig. 6.3 3-D scaling....................................................................................................................................... 84
Fig. 6.4 Parallel projection of an object to the view plane........................................................................... 86
Fig. 6.5 Perspective projection of an object to the view plane..................................................................... 87
Fig. 7.1 Surrounding polygon....................................................................................................................... 94
Fig. 7.2 Overlapping or intersecting polygon............................................................................................... 95
Fig. 7.3 Inside or contained polygon............................................................................................................ 95
VII
Fig. 7.4 Outside or disjoint polygon............................................................................................................. 95
Fig. 8.1 Colour table................................................................................................................................... 107
Fig. 9.1 The interpolation process................................................................................................................113
Fig. 9.2 Interpolation spline and approximation spline...............................................................................114
Fig. 9.3 Fractal surface.................................................................................................................................117
VIII
List of Table
Table 2.1 Differentiation between vector and raster scan display................................................................ 22
IX
Abbreviations
BSP - Binary Space Partitioning
CAD - Computer-Aided Design
CPU - Central Processing Unit
CRT - Cathode-Ray-Tubes
DDA - Digital Differential Analyser
PDCS - Physical Device Coordinate System
SRGP - Simple Raster Graphics Package
WCS - World Coordinate System
X
Chapter I
Introduction to Computer Graphics
Aim
The aim of this chapter is to:
Objectives
The objectives of this chapter are to:
Learning outcome
At the end of this chapter, you will be able to:
1
Computer Graphics
1.1 Introduction
Computer graphics is generally regarded as a branch of computer science that deals with the theory and technology
for computerised image synthesis. It is a tool used for storing, manipulating and correlating data. In ancient times,
before man learnt to talk or write, he used drawings to communicate. Later, with the development of language,
science and mathematics, drawing was reduced to secondary means of communication, to supplement and to illustrate
and soon became a speciality of a draftsmen and a skill of an artist. The medium of advanced computer hardware
and software graphics has made it possible to express data in pictorial form. The picture or graphics may be an
engineering drawing, business graphs, architectural structures, a single frame from an animated movie or a machine
part illustrated for a service manual. It is the fundamental cohesive concept in computer graphics.
In computer graphics, pictures or graphics are presented as a collection of discrete picture elements called pixels.
The pixel is the smallest addressable screen element. It is the smallest piece of the display screen we can control.
The control is achieved by setting the intensity and colour of the pixel which compose the screen. Each pixel on
graphics display represents a region which theoretically contains infinite number of points and not mathematical
points. The process of determining the appropriate pixels for representing picture or graphics object is known as
rasterisation. The process of representing continuous picture or graphics object as a collection of discrete pixels is
called scan conversion. The computer graphics allow rotation, translation, scaling, adding effects and performing
various operations on the picture before displaying it. It allows the user to control and modify contents, structure
and appearance of pictures.
2
• Process control: By the use of computer, it is possible to control various processes in the industry from remote
control room. In such cases, process systems and processing parameters are shown on the computer with
graphic symbols and identification which makes it easy for operator to monitor and control various processing
parameters at a time.
• Cartography – computer graphics is used to represent geographic maps, weather maps, oceanographic charts,
contour maps, population density maps, etc.
3
Computer Graphics
1.2 Lines
• Line is the fundamental element of the picture representation. It is nothing but the position in a plane defined
as either pairs or triplets of numbers depending on whether the data are two or three dimensional.
• Two points would represent a line or edge, and a collection of three or more points a polygon.
• The representation of curved lines is usually accomplished by approximating them by short line segment.
1.4 Vectors
• A vector has a single direction and length.
• Consider the figure below. A vector may be indicated by A and B, where A and B denotes the distance on x and
y axes respectively.
• Unlike line segment, vector does not have a fixed position in the space.
• The vector does not tell us the starting point. It gives the user the direction and how far to move.
4
1.5 Pixels and Frame Buffers
• In raster scan display, a special area of memory is dedicated to graphics only. This memory area is called as
frame buffer.
• It holds the set of intensity values for all the screen points.
• The stored intensity values are retrieved from frame buffer and displayed on the screen one row at a time.
• Each screen point is referred to as a pixel or pel.
• The user can specify the pixel position on the screen by specifying row and column number.
• Intensity range for pixel positions depends on the capability of the raster system.
• It can be a black and white system or colour system.
• Only one bit per pixel is needed to control the intensity of the pixel position since, each pixel position in black
and white system is either on or off.
• When colour and intensity variations are displayed, additional bits are required.
• Upto 24 bits per pixel are included in high quality display system, which can require several megabytes of
storage space for frame buffer.
• The frame buffer is called a bitmap on a black and white system with one bit per pixel.
• The frame buffer is referred as a pixmap for systems with multiple bits per pixel.
5
Computer Graphics
In the figure below, we can see that the 45° line is straight but its width is not constant.
m=
The above differential expression can be used to obtain a rasterised straight line. For any given x interval Δx along
a line, we can compute the corresponding y interval Δy from above equation as:
Δy =
Δx = Δy
Once the intervals are known, the values for next x and next y on the straight line can be obtained as follows:
and =
= +
6
Above two equations represent a recursion relation for successive values of x and y along with the required line.
Such a way of rasterising a line is called a digital differential analyser (DDA).
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main ( )
{
float x, y, x1, y1, x2, y2, dx, dy, length/
int i, gd, gm/
clrscr ( )/
/* read two end points of line
- - - - - - - - - - - - - - - - - - - - - - - - */
printf (“Enter the value of x1 : \t”);
scanf (“%f”, &x1);
printf (“Enter the value of y1 : \t”);
scanf (“%f”, &y1);
printf (“Enter the value of x2 : \t”);
scanf (“%f”, &x2);
printf (“enter the value of y2 : \t”);
scanf (“%f” &y2);
/* initialise graphics mode
- - - - - - - - - - - - - - - - - - - - - - - - */
detectgraph (&gd, &gm);
initgraph (&gd, &gm, “ “);
dx=abs (x2-x1);
dy=abs (y2-y1);
if (dx ≥ dy)
{
length = dx;
}
else
{
length = dy;
}
dx = (x2-x1) / length;
dy = (y2-y1) / length;
x = x1 + 0.5; /* Factor 0.5 is added to round the value */
y = y1 + 0.5; /* Factor 0.5 is added to round the value */
i = ; /* Initialise loop counter */
while (i ≤ length)
{
putpixe1 (x, y, 15);
x = x + dx;
y = y + dy;
i = i + 1;
delay (100); /* Delay is purposely inserted to see
Observe the line process */
}
7
Computer Graphics
getch ( );
closegraph ( );
}
8
1.8.1 ‘C’ Code for Bresenham’s Line Drawing Algorithm
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main ( )
{
float x, y, x1, y1, x2, y2, dx, dy, e;
int i, gd, gm;
clrscr ( );
do
{
putpixel (x, y, 15);
while (e ≥ 0)
{
y =y + 1;
e = e – 2 * dx;
}
x = x + 1;
e = e + 2 * dy;
i = i + 1;
}
while (i ≤ dx);
getch ( );
closegraph ( );
}
9
Computer Graphics
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main ( )
{
float p;
int i, gd, gm, x, y;
int r;
/* initialse graphics
- - - - - - - - - - - - - - - - - - - - - - - - */
detectgraph )&gd, &gm);
initgraph (&gd, &gm, “ “);
/* Read the radius
- - - - - - - - - - - - - - - - - - - - - - - - */
printf (“Enter the radius of the circle :”);
10
scanf (“%d”, &r);
x=0;
y=r;
p = 1.25 – r;
do
{
putpixel (200+x, 200+y, 15);
putpixel (200+y, 200+x, 15);
putpixel (200+x, 200 - y, 15);
putpixel (200+y, 200 - x, 15);
putpixel (200 - x, 200 - y, 15);
putpixel (200 – x, 200+y, 15);
putpixel (200 – y, 200+x, 15);
putpixel (200 – y, 200 – x, 15);
if (p < 0)
{
x = x+1;
y = y;
p = p+2 * x+1;
}
else
{
x = x+1;
y = y+1
p = p+2 (x – y) +1;
}
delay (10000);
}
while (x < y);
getch ( );
closegraph ( );
}
11
Computer Graphics
#include<srdio.h>
#include<graphics.h>
#include<math.h>
main ( )
{
long d1, d2;
int i, gd, gm, x, y;
long rx, ry, rxsq, tworxsq, tworysq, dx, dy;
/* initialise graphics
- - - - - - - - - - - - - - - - - - - - - - - - */
detectgraph (&gd, gm);
initgraph (&gd, &gm, “ “);
rxsq = rx * rx;
rysq = ry * ry;
tworxsq = 2 * rxsq;
two + 2 * rysq;
x = 0;
y = ry;
12
d1 = rysq – rxsq * ry + (0.25 * rxsq);
dx = tworysq * x;
dy + two * y;
do
{
putpixel (200 + x, 200 + y, 15);
putpixel (200 – x, 200 – y, 15);
putpixel (200 + x, 200 -, 15);
putpixel (200 – x, 200 + y, 15);
if )d1 < 0)
{
x = x + 1;
y = y;
dx = dx + tworysq;
d1 = d1 + dx + rysq;
}
else
{
x = x + 1;
y = y – 1;
dx = dx + tworysq;
dy = dy – twoexsq;
d1 = d1 + dx – dy + rysq;
}
delay (10);
}
while (dx < dy);
d2 = rysq* (x + 0.5) * (x + 0.5) + rxsq* (y – 1) * (y-1) – rxsq * rysq;
do
{
putpixel (200 + x, 200 + y, 15);
putpixel (200 – x, 200 – y, 15);
putpixel (200 – x, 200 + y, 15);
putpixel (200 – x, 200 + y, 15);
if (d2 > 0)
{
x = x;
y = y – 1;
dy = dy – tworxsq;
d2 = d2 – dy + rxsq;
}
else
{
x = x + 1;
y = y – 1;
dy = dy – tworxsq;
dx = dx + tworusq;
d2 = d2 + dx – dy + rxsq;
}
} while (y > 0);
getch ( );
closegraph ( );
}
13
Computer Graphics
• The above figure shows the implementation of frame buffer using shift register.
• One shift register is required per pixel on a scan line and the length of shift register in bits is equal to number
of scan lines.
• Here, there are 8 pixels per scan line and there are in all 5 scan lines. Therefore, 8 shift registers, each of 5 bit
length are used to implement frame buffer.
• The synchronisation between the output of the shift register and the video scan rate is the maintained data
corresponding to particular scan line is displayed correctly.
• Both, rotating memory and shift register frame buffer implementations have low levels of interactivity.
• The interactivity in rotating memory is limited due to disk access time and it is reduced in shift register
implementations because changes can only be made as buts are being added to the register.
• The above figure shows the frame buffer graphics system. It contains CPU, frame buffer, display controller and
video monitor.
• An application program running in the computer updates the frame buffer as per the picture information.
• The display controller cycles through the frame buffer in scan line order (top to bottom) and pass the corresponding
information to the video monitor to refresh the display.
14
Summary
• Computer graphics is generally regarded as a branch of computer science that deals with the theory and technology
for computerised image synthesis.
• The process of determining the appropriate pixels for representing picture or graphics object is known as
rasterisation.
• Line is the fundamental element of the picture representation. It is nothing but the position in a plane defined
as either pairs or triplets of numbers depending on whether the data are two or three dimensional.
• When we consider the piece of line, i.e., only two points which lie between two endpoints, then it is called a
line segment.
• A vector has a single direction and length.
• In raster scan display, a special area of memory is dedicated to graphics only. This memory area is called as
frame buffer.
• Each screen point is referred to as a pixel or pel.
• The process of turning on the pixels for a line segment is called vector generation.
• Digital differential analyser (DDA) is the vector generation algorithm which steps along the line to determine
the pixel which should be turned on.
• Bresenham’s line algorithm uses only integer addition, subtraction and multiplication by 2.
• The basic principle of Bresenham’s line algorithm is to select the optimum raster locations to represent a straight
line.
• The midpoint circle drawing algorithm uses the eight way symmetry of the circle to generate it.
• The midpoint ellipse drawing algorithm uses the four way symmetry of the ellipse to generate it.
• Frame buffer is implemented using rotating random access semiconductor memory.
References
• Introduction to Computer Graphics. [Online] Available at: <http://train-srv.manipalu.com/wpress/?p=75678>
[Accessed 19 May 2011].
• Bandukwala, F., Introduction to Computer Graphics. [Pdf] Available at: <http://cseweb.ucsd.edu/classes/wi03/
cse167/lectures/lec2.pdf> [Accessed 21 June 2013].
• Oresoft LWC, 2010. Introduction To Computer Graphics Part 1. [Video online] Available at: <http://www.
youtube.com/watch?v=zyM0xvpzg9c> [Accessed 21 June 2013].
• nptelhrd, 2008. Lecture - 1 Introduction to computer graphics. [Video online] Available at: <http://www.youtube.
com/watch?v=fwzYuhduME4&list=PL338D19C40D6D1732> [Accessed 21 June 2013].
• Shirley, P., 2009. Fundamentals of Computer Graphics. 3rd ed., A K Peters.
• Foley, J. D., 1995. Computer graphics – Principles and Practice, 2nd ed., Addison-Wesley Publishing Company,
Inc.
Recommended Reading
• Watt, A., 1999. 3D Computer Graphics. 3rd ed., Addison Wesley.
• Akenine-Moller, T., 2008. Real-Time Rendering. 3rd ed., A K Peters/CRC Press.
• Paquette, A., 2008. Computer Graphics for Artist: An Introduction. 1st ed. Springer.
15
Computer Graphics
Self Assessment
1. Which of the following statements is true?
a. Computer graphics is generally regarded as a branch of computer science that deals with the theory and
technology for image synthesis.
b. Computer graphics is generally regarded as a branch of computer science that deals with the theory and
technology for computerised image synthesis.
c. Computer graphics is generally regarded as a branch of computer technology that deals with the theory for
computerised image synthesis.
d. Computer graphics is generally regarded as a branch of science that deals with the theory and technology
for computerised image synthesis.
2. The process of representing continuous picture or graphics object as a collection of discrete pixels is called
___________.
a. scan conversion
b. rasterisation
c. frame buffer
d. vector generation
16
7. What is the slope of a straight line?
a. Δy =
b. m =
c. m =
d. Δy =
8. The frame buffer is referred to as a _________ for systems with multiple bits per pixel.
a. pixmap
b. pel
c. pixel
d. resolution
10. One shift register is required per pixel on a scan line and the length of __________ in bits is equal to number
of scan lines.
a. line segment
b. shift register
c. vectors
d. frame buffers
17
Computer Graphics
Chapter II
Graphics Primitives
Aim
The aim of this chapter is to:
Objectives
The objectives of this chapter are to:
Learning outcome
At the end of this chapter, you will be able to:
18
2.1 Display Devices
The display devices are also known as output devices. An output device is a piece of computer hardware equipment
used to communicate the results of data processing carried out by a computer system to the outside world.
The most commonly used output devices in graphics system is a video monitor. The operation of most video monitors
is based on the standard cathode ray tube (CRT) design.
• The deflection system of the cathode ray tube consists of two pairs of parallel plates, referred as the vertical
and horizontal deflection plates.
• The voltage applied to vertical plates controls the vertical deflection of the electron beam and voltage applied
to the horizontal deflection plates controls the horizontal deflection of the electron beam.
19
Computer Graphics
• There are two ways which are used to produce images on the CRT screen.
Vector scan/random scan
Raster scan
• From the above figure, we can see the typical vector display architecture.
• It consists of display controller, Central Processing Unit (CPU), display buffer memory and a CRT.
• A display controller is connected as an input or output peripheral to the central processing unit (CPU).
• The display buffer memory stores the computer produced display list or display program.
• The display controller interprets commands for plotting points, lines and characters and sends digital and point
coordinates to a vector generator.
• The vector generator then converts and sends digital coordinate values to analog voltages for beam-deflection
circuits that display an electron beam writing on the CRT’s phosphor coating.
• In vector display, beam is deflected from end point to end point, hence this technique is also called random
scan.
• We know as beam strikes phosphor it emits light.
20
• But a phosphor light decays after few milliseconds and therefore, it is necessary to repeat through the display
list to refresh the phosphor at least 30 times per second to avoid flicker.
• As display buffer is used to store display list and it is used for refreshing the display buffer memory, it is also
called refresh buffer.
• As shown in the above figure, the display is stored in the form of 1s and 0s in the refresh buffer.
• The video controller reads this refresh buffer and produces the actual image on the screen.
• It does this by scanning one scan line at a time, from top to bottom and then back to the top.
• Raster scan is the most common method of displaying images on the CRT screen.
• In this method, the horizontal and vertical deflection signals are generated to move the beam all over the screen
in a pattern as shown in the figure below.
21
Computer Graphics
• Here, the beam is swept back and forth from the left to the right across the screen.
• When the beam is moved from the left to the right, it is ON and when it is moved from the right to the left, the
beam is OFF.
• When the beam reaches the bottom of the screen, it is turned OFF and is rapidly retraced back to the top left
to start again.
• A display produced in this way is called raster scan display.
• In the raster scan display, the screen image is maintained by repeatedly scanning the same image. This process
is known as refreshing of screen.
• In raster scan display, a special area of memory is dedicated to graphics only. This memory area is called frame
buffer.
• It holds the set of intensity values for all the screen points. The stored intensity values are retrieved from frame
buffer and displayed on the screen one row at a time.
• The beam is moved between the end points • The beam is moved all over the screen, one scan line at
of the graphics primitives. a time.
• Vector display flickers when the number of • The refresh process is independent of the complexity of
primitives in the buffer becomes too large. the image.
• Graphics primitives are specified in terms of their endpoints
• Scan conversion is not required. and must be scan converted into their corresponding pixels
in the frame buffer.
• Because each primitive must be scan-converted, real time
• Scan conversion hardware is not required. dynamics is far more computational and requires separate
scan conversion hardware.
• It can display mathematically smooth lines, polygons
• It draws continuous and smooth lines. and boundaries of curved primitives only one by
approximating them with pixels on raster grid.
22
2.2 Interactive Devices
An interactive device in other words is called the input device which gives input to the graphics system and provides
necessary feedback to the user about the accepted input. Interactive devices include:
• keyboard
• mouse
• trackball
• joystick
• data glove
• touch panels
• light pen
2.2.2 Mouse
Mouse is an additional input, pointed device. This device enables the user to control the mouse pointer by moving
the device around on a flat surface.
2.2.3 Trackball
A trackball works like an upside-down mouse as a pointing device. Trackball contains an exposed ball that can
be rolled with an index finger or thumb to move the pointer around the screen. A trackball needs less space than a
mouse as it is not necessary to move whole device.
2.2.4 Joystick
A joystick is a personal computer input device consisting of a handheld stick that pivots about one end and transmits
its angle in two or three dimensional to a computer.
23
Computer Graphics
y 0 x
0 x y
• SRGP supports various graphics primitives such as lines, polynomials, circles, ellipse and text.
When successive vertices are connected by sequence of lines, the line is called polyline. The SRGP supports two
separate procedures for polyline. Procedures store the coordinate information in arrays.
[Here, xArray and yArray are pointers to user declared arrays for x and y coordinates respectively. vertexCount
specified the number of vertices in the Polyline.]
24
Fig. 2.7 Polyline drawing
25
Computer Graphics
Ant rectangle can be specified as a polygon having four vertices, but an upright rectangle (one whose edges are
parallel to the edges of the screen) can also be specified with the SRGP “rectangle primitive using only two vertices
(bottom left and top right corners)
Top, Right
Bottom, Left
Procedure 1: Void SRGP_rectangleCoord (int leftx, int bottom, int rightx, int topy);
Procedure 2: Void SRGP_rectanglePt (point bottomLeft, topRight);
Procedure 3: Void SRGP_rectangle (rectangle rect):
[Here, rectangle is defined structure having coordinate information of bottomleft and topright
vertices.
Typedef struct
{point bottomLeft, topRight:
}rectangle;]
2.4.2 Attributes
There are two types of Attributes. They are as follows:
Line Attributes
• The SRGP provides attributes for line drawing to control their appearance.
• These attributes are line style, line width, colour and pen style.
• There are separate procedures to set the attributes.
• Once the attributes are set, graphics primitive procedures follow set attributes to draw the graphics.
26
Procedure 4: Void SRGP_loadColourTable (int start, int count, unsigned *r, unsigned *g, unsigned *b)
procedure 5: Void SRGP_loadCommonColour (int entry, char *ColourName);
Marker Attributes
Marker has two attributes: size and style.
Concave polygon: A concave polygon is a polygon in which the line segment joining any two points within
the polygon may not lie completely inside the polygon.
27
Computer Graphics
Fill Attributes
There are two attributes supported by SRGP for filling the regions: fill style and fill pattern.
28
Fig. 2.13 Vector refresh display system
• From the fig. 2.13, we can say that display files provide an interface between the image specification process
and the image display process.
• It also describes image in a compact format.
• The concept of display file may be applied to devices other than refresh displays. Such files are called pseudo
display files, or metafiles.
• Fig. 2.14 shows the structure of display file. It contains series of commands.
• Each display file command contains two fields, an operation code (opcode) and operands.
• Opcode identifies the command such as draw line, move cursor, etc., and operand provides the coordinates of
a point to process the command.
• From the above figure, we can see that the display process is divided into two steps.
• First the image is stored in the display file structure and then it is interpreted by an appropriate interpreter to
get the actual image.
• Instead of this, if we store actual image for particular display it may not run on other display.
• To achieve the device independence, the image is stored in the raw format, i.e., in the display file format and
then it is interpreted by an appropriate interpreter to run on required display.
• Another advantage of using interpreter is that saving raw image takes much less storage space than saving the
picture itself.
29
Computer Graphics
30
Summary
• The display devices are also known as output devices. An output device is a piece of computer hardware equipment
used to communicate the results of data processing carried out by a computer system to the outside world.
• The most commonly used output devices in graphics system is a video monitor.
• A CRT is an evaluated glass tube.
• Raster scan is the most common method of displaying images on the CRT screen.
• In raster scan display a special area of memory is dedicated to graphics only. This memory area is called frame
buffer.
• The scanner is a device, which can be used to store drawings, graphs, photos or text available in printed form
for computer processing.
• Simple Raster Graphics Package (SRGP) is a device independent of graphics package which supports graphics
primitives such as lines, rectangles, circles, ellipses and text strings.
• Polyline is a chain of connected line segments.
• The SRGP provides attributes for line drawing to control their appearance.
• A convex polygon is a polygon in which the line segment joining any two points within the polygon lies
completely inside the polygon.
• A concave polygon is a polygon in which the line segment joining any two points within the polygon may not
lie completely inside the polygon.
• In some graphics systems a separate computer is used to interpret the commands in the display file. Such
computer is known as display processor.
References
• Shirley, P., 2009. Fundamentals of Computer Graphics. 3rd ed., A K Peters.
• Xiang, Z., 2000. Schaum’s Outline of Computer Graphics. 2nd ed., McGraw-Hill.
• UNIT 2 GRAPHIC PRIMITIVES, [Pdf] Available at: <http://vedyadhara.ignou.ac.in/wiki/images/f/f6/B1U2mcs-
053.pdf> [Accessed 21 June 2013].
• Shoaff, W., 2002. Graphics Primitives, [Pdf] Available at: <http://cs.fit.edu/~wds/classes/prog-graphics/Lectures/
primitives.pdf> [Accessed 21 June 2013].
• Barfield, A., 2010. Class: CSC 370: Computer Graphics, [Video online] Available at: <http://www.youtube.
com/watch?v=fKz87vfz4E0> [Accessed 21 June 2013].
• Jarina, V., 2008. Troll2D Primitives/Graphics Test, [Video online] Available at: <http://www.youtube.com/
watch?v=Gh9_6W8BSJw> [Accessed 21 June 2013].
Recommended Reading
• Parent, R., October 11, 2007. Computer Animation: Algorithms and Techniques. 2nd ed., Morgan Kaufmann.
• Godse, A. P., 2008. Computer Graphics. 4th ed., Technical Publication.
• Xiang, Z., September 8, 2000. Schaum’s Outline of Computer Graphics. 2nd ed., McGraw-Hill.
31
Computer Graphics
Self Assessment
1. The display devices are also known as _________ devices.
a. output
b. input
c. raster scan
d. random scan
6. ________ is a device independent of graphics package which supports graphics primitives such as lines,
rectangles, circles, ellipses and text strings.
a. CPU
b. CRT
c. Simple Raster Graphics Package (SRGP)
d. Scanner
32
7. Which of the following statements is false?
a. Most of the graphics packages do not use Cartesian coordinate systems.
b. The video controller reads this refresh buffer and produces the actual image on the screen.
c. The main task of display processor is to digitise a picture definition given in an application program into a
set of pixel intensity values for storage in the frame buffer.
d. Most of the graphics packages use Cartesian coordinate systems.
8. In raster scan display, the special area of memory that is dedicated only to graphics, is called as ______.
a. Frame
b. frame buffer
c. buffer
d. operands
10. In some graphics systems, a separate computer is used to interpret the commands in the display file. Such
computer is known as _________.
a. raster scan display
b. random scan display
c. pseudo files
d. display processor
33
Computer Graphics
Chapter III
Polygons
Aim
The aim of this chapter is to:
• define polygons
Objectives
The objectives of this chapter are to:
Learning outcome
At the end of this chapter, you will be able to:
• identify polygon
• understand algorithms
34
3.1 Introduction
A polyline is a chain of connected line segments. It is specified by giving the vertices x, y, z.... and so on. The
vertex is called the initial or starting point and the last vertex is called the final or terminal point. (Refer to the
figure below). When starting point and terminal point of any polyline is same, i.e., when polyline is closed, then it
is called polygon. (Refer fig. 3.2)
• Concave polygon: A concave polygon is a polygon in which the line segment joining any two points within the
polygon may not lie completely inside the polygon.
35
Computer Graphics
36
DF_y [i] ← AY [0]
[Enter last line command]
5. Stop
37
Computer Graphics
• In some cases, an 8-connected algorithm is more accurate than the 4-connected algorithm.
#include<stdio.h>
#include<graphics.h>
main ( )
{
int gd, gm;
38
3.5.1.3 Flood Fill Algorithm
• Sometimes, it is required to fill in an area that is not defined within a single colour boundary.
• In such cases, we can fill areas by replacing a specified interior colour instead of searching for a boundary colour.
This approach is called a flood fill algorithm.
• Like boundary fill algorithm, here also we start with some seed and examine the neighbouring pixels.
• However, here pixels are checked for a specified interior colour instead of boundary colour and they are replaced
by new colour.
• Using either a 4-connected or 8-connected approach, we can step through pixel positions until all interior point
have been filled.
}
}
39
Computer Graphics
• This procedure is repeated with changing the seed pixel above and below the line just drawn until complete
polygon is filled.
• With this efficient method, we have to stack only a beginning position for each horizontal pixel span, instead
of stacking all unprocessed neighbouring positions around the current positions.
Scan line
x
6 9 12 15
• The important task in the scan line algorithm is to find the intersection points of the scan line with the polygon
boundary.
• When intersection points are even, they are sorted from left to right, paired and pixels between paired points
are set to the fill colour.
• But in some cases intersection point is a vertex.
• When scan line intersects polygon vertex a special handling is required to find the exact intersection points.
• To handle such cases, we must look at the other endpoints of the two line segments of the polygon which meet
at this vertex.
• If these points lie on the same (up and down) side of the scan line, then the point in question counts as an even
number of intersections.
• If they lie on opposite sides of the scan line, then the point is counted as single intersection.
Fig. 3.8 Intersection points along the scan line that intersect polygon vertices
3.5.2.1 ‘C’ Code for Scan Line Algorithm for Filling Polygon
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
40
/* defining the structure to store edges
----------------------------------------------*/
struct edge
{
int x1;
int y1;
int x2;
int y2;
int flag;
};
void main ( )
{
int gd = DETECT, gm, n, i, j, k;
struct edge ed [10], temped;
float dx, dy, m[10], x_int[10], inter_x[10];
initgraph (&gd, &gm, “ “);
/* Read the vertices of the polygon and also find Ymax and Ymin
------------------------------------------------------*/
printf (“Enter the vertices: \n”);
for (i=0; i< n; i++)
{
printf (“x[%d] : “, i);
scanf (“%d”, &x[i]);
printf (“y[%d] : “, i);
scanf (“%d”, &y[i]);
if (y[i] > ymax)
ymax = y[i];
if (y[i] < ymin)
ymin = y[i];
ed[i].x1 = x[i];
ed[i].y1 = y[i];
}
41
Computer Graphics
if(ed[j].y1<ed[j+1].y1)
temped = ed[j];
ed[j] = ed[j+1];
ed[j+1] = temped;
if(ed[j].y1 = =ed[j+1].y1
{
if (ed[j].y2<ed[j+1].y2)
{
temped = ed[j];
ed[j] = ed [j+1];
ed[j+1] = temped;
42
}
if(ed[j+1] = temped;
}
if(ed[j].x1<ed[j+1].x1)
{
temped = ed[j];
ed[j] = ed[j+1];
ed[j+1] = temped;
}
}
}
}
}
/* Calculating 1/slope of each edge and storing top x
coordinate of the edge
------------------------- */
for (i=0; i<n; i++)
{
dx = ed[i].x2 – ed[i].x1;
dy = ed[i].y2 – ed[i].y1;
if(dy = =0)
{
m[i] = 0;
}
else
{
m[i] = dx/dy;
}
inter_x[i] = ed[i].x1;
}
yy = ymax;
while(yy>ymin)
{
/* Marking active edges
--------------------------*/
for(i=0; i<n; i++)
{
if(yy > ed[i].y2 && yy <= ed[i].y1)
ed[i].flag = 1;
43
Computer Graphics
else
ed[i].flag = 0;
}
}
if(ed[i].flag = = 1)
{
if(yy = =ed[i].y1)
x_int[j] = ed[i].x1;
j++;
if(ed[i-1].y1 = =yy && ed[i-1].y1<yy)
{
x_int[j] = ed[i].x1;
j++;
}
if_ed[i-1].y1 = = yy && ed[i+1].y1<yy)
{
x_int[j] = ed[i].x1;
j++;
}
}
else
44
{
x_int[j] = inter_x[i]+(-m[i]);
inter_x[i] = x_int[j[;
j++;
}
}
}
{
if(x_int[k]>x_int[k+1])
{
temp = x_int[k];
x_int[k] = x_int[k=1];
}
}
}
/* Extracting pairs of x values to draw lines
-------------------------------------------*/
line(x_int[i],yy,x_int[i+1],yy);
}
yy - -;
delay(50);
}
getch ( );
}
45
Computer Graphics
46
Summary
• A polyline is a chain of connected line segments. It is specified by giving the vertices x, y, z.... and so on.
• The vertex is called the initial or stating point and the last vertex is called the final or terminal point.
• The classification of polygons is based on where the line segment joining any two points within the polygon
is going to lie.
• A convex polygon is a polygon in which the line segment joining any two points within the polygon lies
completely inside the polygon.
• A concave polygon is a polygon in which the line segment joining any two points within the polygon may not
lie completely inside the polygon.
• Filling the polygon means highlighting all the pixels which lie inside the polygon with any colour than background
colour.
• Algorithms that fill interior-designed regions are called flood-fill algorithms.
• Algorithms that fill boundary-defined regions are called boundary-fill algorithms or edge-fill algorithms.
• Boundary defined regions may be either 4-connected or 8-connected.
• The important task in the scan line algorithm is to find the intersection points of the scan line with the polygon
boundary.
• Filling an area with a rectangular pattern is called tiling and rectangular patterns are sometimes referred to as
tiling patterns.
• Display file store the information about lines and character whereas scan conversion gives the information about
every pixel on the screen.
References
• Polygon Filling. [Online] Available at: <http://www.cs.uic.edu/~jbell/CourseNotes/ComputerGraphics/
PolygonFilling.html> [Accessed 21 June 2013].
• Computer Graphics. [Pdf] Available at: <http://www.cs.arizona.edu/classes/cs433/spring12/ScanC.prn.pdf>
[Accessed 21 June 2013].
• GuerrillaCG, 2008. The Polygon. [Video online] Available at: <http://www.youtube.com/watch?v=-bZ7gstIWyI>
[Accessed 21 June 2013].
• nptelhrd, 2008. Lecture -5 Polygon Clipping and Polygon Scan Conversion. [Video online] Available at: <http://
www.youtube.com/watch?v=lZJI_Fth66A> [Accessed 21 June 2013].
• Foley, J. D., 1996. Computer Graphics: Principles and Practice, Second Edition in C, 2nd ed., Addison-Wesley
Professional.
• Desai, A. A., 2008. Computer Graphics, PHI Learning Pvt. Ltd.
Recommended Reading
• McConnell,J. J., 2006. Computer Graphics: Theory Into Practice, Jones & Bartlett Learning.
• Bhatia, P. K., 2008. Computer Graphics, I. K. International Pvt Ltd.
• Alavala, C. R., 2009. Computer Graphics, PHI Learning Pvt. Ltd.
47
Computer Graphics
Self Assessment
1. A polyline is a chain of connected ________.
a. line segments
b. lines
c. polygons
d. points
3. When starting point and terminal point of any polyline is same i.e., when polyline is closed then it is called
________.
a. line
b. quadrilateral
c. polygon
d. segment
5. What is known to be inside the polygon and highlight outward from the point until we encounter the boundary
pixels?
a. Boundary fill
b. Seed fill
c. Pattern fill
d. Flood fill
48
7. Which of the following statements is true?
a. Algorithms that fill boundary-defined regions are called fill algorithms or edge-fill algorithms.
b. Algorithms that fill boundary-defined regions are called flood fill algorithms or edge-fill algorithms.
c. Algorithms that fill boundary-defined regions are called boundary-fill algorithms or edge-fill algorithms.
d. Algorithms that fill boundary-defined regions are called pattern fill algorithms or edge-fill algorithms.
9. ________ is a small group of pixels with a fixed colour combination used to fill the particular area in the
picture.
a. Pattern
b. Shape
c. Polygon
d. Polyline
49
Computer Graphics
Chapter IV
2D Transformations
Aim
The aim of this chapter is to:
• define 2d transformation
Objectives
The objectives of this chapter are to:
Learning outcome
At the end of this chapter, you will be able to:
• solve matrices
50
4.1 Matrices
• In computer graphics, images are generated from a series of line segments which are represented by the
coordinates of their end points.
• Due to this we can make changes in an image by performing mathematical operations on these coordinates.
When any changes are made we say that the image is transformed.
• To study various image transformations, mathematical tools like matrix multiplication is needed.
• Matrix is a two dimensional array of number.
Example:
The elements in the matrix are identified by specifying the row and column number.
Example:
A=
In the above example, element 8 is identified as A (3, 2), i.e., element 8 is in the 3rd row and 2nd column of the matrix
A.
Consider:
B=
Here we can multiply matrix A and B because matrix A has 3 columns and matrix B has 3 rows. Matrix multiplication
is not commutative like number multiplication that is, while we can multiply A times B, we cannot multiply B times
A, because B has 2 columns and A has 3 rows. When we multiply two matrices we get resultant matrices such that
it has same number of rows as the first matrix of the two being multiplied and the same number of columns as the
second matrix. Therefore, multiplication of A and B gives 3 x 4 resultant C matrix.
C (i. K) =
In the example, the element C (1, 1) is found by multiplying each element of the first row of A by the corresponding
element of the first column of B and adding these products together.
51
Computer Graphics
Similarly,
C (1, 2)= A (1, 1) B (1, 2) + A (1, 2) B (2, 2) + A (1, 3) B (3, 2)
= (1) (2) + (2) (0) + (3) (1)
=5
C=
Example:
4.2.1 Translation
• Translation is a process of changing the position of an object in a straight-line path from one co-ordinate location
to another.
• We can translate a two dimensional point by adding translation distances, and , to the original coordinate
position (x, y) to move the point to a new position (x′, y′). (Refer to the figure below.)
x′ = x + ...................... (i)
y′ = y + ...................... (ii)
P= P′ = T=
52
• This allows us to write the two dimensional translation equations in the matrix form:
P′ = P + T...................... (iii)
4.2.2 Rotation
• A two dimensional rotation is applied to an object repositioning it along a circular path in the xy plane.
• To generate a rotation, we specify a rotation angle θ and the position of the rotation about which the object is
to be rotated.
• Let us consider the rotation of the object about the origin as shown in the figure below.
Here, r is the constant distance of the point from the origin, angle φ is the original angular position of the point from
the horizontal, and θ is the rotation angle. Using standard trigonometric equations, we can express the transformed
coordinates in terms of angles θ and φ as:
x′ = r cos (φ + θ) = r cos φ cos θ – r sin φ sin θ
y′ = r sin (φ + θ) = r cos φ sin θ + r sin φ cos θ......................... (iv)
The original coordinates of the point polar coordinates are given as:
x = r cos φ
y = r sin φ......................... (v)
Substituting equations (v) into (iv), we get the transformation equations for rotating a point (x, y) through an angle
θ about the origin as:
x′ = x cos θ – y sin θ
y′ = x sin θ + y cos θ......................... (vi)
P′ = P∙R......................... (vii)
R= ......................... (viii)
It is important to note that positive values for the rotation angle define counter-clockwise rotations about the rotation
point and negative values rotate objects in the clockwise sense.
For negative values of θ, i.e., for clockwise rotation, the rotation matrix becomes:
R=
53
Computer Graphics
R=
4.2.3 Scaling
• A scaling transformation changes the size of an object.
• This operation can be carried out for polygons by multiplying the coordinate values (x, y) of each vertex by
scaling factors and to produce the transformed coordinates (x′, y′).
x′ = x ∙
and y′ = y ∙ .........................(x)
Scaling factor scales object in the x direction and scaling factor scales object in the y direction. The equation
(x) can be written in the matrix form as:
= [x, y]
• Any positive numeric values are valid for scaling factors and .
• Values less than 1 reduce the size of the objects and values greater than 1 produce an enlarged object.
• For both, and values equal to 1, the size of object does not change.
• To get uniform scaling it is necessary to assign same value for and .
• Unequal values for and result in a differential scaling.
54
4.3 Homogeneous Coordinates
• In design and picture formation process, many times we may require to perform translation, rotations and scaling
to fit the picture components into their proper positions.
• The basic transformations can be expressed in the general matrix form as:
P′ = P ∙ + ......................... (xii)
For translation: P′ = P ∙ +
= Translation factor
For rotation: P′ = P ∙ +
i.e.,
=0
For scaling: P′ = P ∙ +
• Now to produce a sequence of transformations with above equations, such as translation followed by rotation
and then scaling, we must calculate the transformed coordinate one step at a time.
• First, coordinates are translated, and then these translated coordinates are scaled, and finally the scaled coordinates
are rotated.
• But this sequential transformation process is not efficient.
• More efficient approach is to combine sequential transformation into one transformation, so that the final
coordinate positions are obtained directly from initial coordinates.
• In order to combine sequence of transformations, we have to eliminate the matrix addition associated with
translation terms in .
• To achieve this, we have to represent matrix as 3 x 3 matrix, instead of 2 x 2 introducing an additional
dummy coordinate W.
• Here, points are specified by these numbers instead of two. This coordinate system is called homogeneous
coordinate system.
• The homogeneous coordinate system allows us to express all transformation equations as matrix
multiplication.
• The homogeneous coordinate is represented by a triplet ( , , W),
x= and y =
55
Computer Graphics
T= ......................... (xiii)
Therefore, we get:
= ......................... (xiv)
R= ......................... (xv)
Therefore, we get:
= ......................... (xvi)
S=
Therefore, we get:
= ......................... (xvii)
56
Fig. 4.4 Rotation about an arbitrary point
The rotation matrix for counter clockwise rotation of point about the origin is given as:
R=
The translation matrix to move the centre point back to its original position is given by:
Therefore, the overall transformation matrix for a counter clockwise rotation by an angle θ about the point ( ,
is given as:
∙R∙ =
∙R∙ =
......................... (xviii)
57
Computer Graphics
Summary
• Matrix multiplication is more complex than the simple product of two numbers.
• In computer graphics, images are generated from a series of line segments which are represented by the
coordinates of their end points.
• The generalised formula for matrix multiplication is given by, C (i. K) = .
• The square matrix which has all the elements equal to 0 except the elements of the main diagonal, which are
all 1 is called identity matrix.
• Translation is a process of changing the position of an object in a straight-line path from one co-ordinate location
to another.
• A scaling transformation changes the size of an object.
• In design and picture formation process, many times we may require to perform translation, rotations, and
scaling to fit the picture components into their proper positions.
References
• Transformation and Projection. [Pdf] Available at: <http://www.magix.in/pdfs/bca3/Notes/cg/chapter3.pdf>
[Accessed 19 June 2013].
• Transformations in 2 Dimensions . [Online] Available at: <http://www.cs.uic.edu/~jbell/CourseNotes/
ComputerGraphics/2DTransforms.html> [Accessed 21 June 2013].
• nptelhrd, 2009. Lecture - 8 2D Transformations. [Video online] Available at: <http://www.youtube.com/
watch?v=iWxS2zpaRjk> [Accessed 21 June 2013].
• NoyoNLighten, 2012. Computer Graphics- 2D Transformations- I. [Video online] Available at: <http://www.
youtube.com/watch?v=vBKX_bnQDdw> [Accessed 21 June 2013].
• Guha, S., 2011. Computer Graphics Through OpenGL: From Theory to Experiments, CRC Press.
• Klawonn, F., 2012. Introduction to Computer Graphics: Using Java 2D and 3D, 2nd ed., Springer.
Recommended Reading
• Govil, S., 2004. Principles of Computer Graphics: Theory and Practice Using OpenGL and Mayaо,
Springer.
• Jones, H., 2001. Computer Graphics.: Through Key Mathematics, Springer.
• Mukherjee, D. P., 2004. Fundamentals Of Computer Graphics And Multimedia, PHI Learning Pvt.
58
Self Assessment
1. Which of the following statements is true?
a. Matrix is a single dimensional array of number.
b. Matrix is a two dimensional array of number.
c. Matrix is a multidimensional array of number.
d. Matrix is not a two dimensional array of number.
4. What is the square matrix which has all the elements equal to 0, except the elements of the main diagonal,
which are all 1 called as?
a. Matrix
b. Matrix multiplication
c. Translation vector
d. Identity matrix
59
Computer Graphics
9. What is the process of changing the position of an object in a straight-line path from one co-ordinate location
to another called as?
a. Scaling
b. Transformation
c. Translation
d. Rotation
a. T =
b. T =
c. T =
d. T =
60
Chapter V
Windowing and Clipping
Aim
The aim of this chapter is to:
Objectives
The objectives of this chapter are to:
Learning outcome
At the end of this chapter, the student will be able to:
61
Computer Graphics
5.1 Introduction
A graphics package allows us to specify which part of a defined picture is to be displayed and where that part is
to be displayed on the display device. The package also provides the use of the scaling, translation and rotation
techniques to generate a variety of different views of a single picture. Different views of a picture can be generated
by applying the appropriate scaling and translation. We have to identify the visible part of the picture for inclusion
in the display image while doing this. This selection process is not straight forward. Certain lines may lie partly
inside or outside the visible portion of the picture. These lines cannot be omitted entirely from the display image
because the image would become inaccurate. (Refer to the figure below). The process of selecting and viewing the
picture with different views is called windowing. The process which divides each element of the picture into its
visible and invisible portions, allowing the invisible portion to be discarded is called clipping.
62
• World coordinate system (WCS) is infinite in extent and the device display area is finite.
• Therefore, to perform a viewing transformation we select a finite world coordinate area for display called a
window.
• An area on a device to which a window is mapped is called as a viewport.
• The window defines what is to be viewed, whereas the viewport defines where it is to be displayed. (Refer to
the figure below.)
63
Computer Graphics
• To avoid this and to make our programs to be device independent, picture coordinates should be defined in some
units other than pixels and use the interpreter to convert these coordinates to appropriate pixel values for the
particular display device. The device independent units are called the normalised device coordinates.
• In these units, the screen measures 1 unit wide and 1 unit length as shown in the fig. 5.5.
• The interpreter uses simple linear formula to convert normalise device coordinates to the actual device
coordinates.
x= x .................. (i)
y= x................... (ii)
where,
x : Actual device x coordinate
y : Actual device y coordinate
: Normalised x coordinate
: Normalised y coordinate
: Width of actual screen in pixels
: Height of actual screen in pixels
• The transformations which map the viewing coordinate to normalised device coordinate are called normalisation
transformation.
• It involves scaling of x and y. Thus, it is also referred to as, scaling transformation.
64
This function generates ViewMatrix for the world to viewing transformation if there is no error in input
parameters.
ViewIndex: Integer identifier for window-viewport pair. Therefore, it refers viewMatrix and corresponding
viewMappingMatrix.
Clipxy : It is assigned with either the value noclip or the value chip. This allows us to turn off clipping if we want
to view the parts of the scene outside the viewport. We can also select noclip to speed up processing when we know
that all of the scene is included in the viewport limits.
SetViewIndex (viewIndex)
This function selects a particular set of options from the viewing table. This view-index selection is applicable to
subsequently specified output primitives.
Ws : Workstation number
5.6 2D Clipping
• The procedure that identifies the portions of a picture that are either inside or outside of a specified region of
space is referred to as clipping.
• The region against which an object is to be clipped is called a clip window or clipping window.
• It usually is in a rectangular shape.
• 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 others are discarded.
65
Computer Graphics
• Each bit position in the region code is used to indicate one of the four relative coordinate positions of the point
with respect to the clipping window: to the left, right, top or bottom. The rightmost bit is the first bit and the
bits are set to 1 based on the following scheme:
Set Bit 1 – if the end point is to the left of the window
Set Bit 2 – if the end point is to the right of the window
Set Bit 3 – if the end point is below the window
Set Bit 4 – if the end point is above the window
• Otherwise, the bit is set to zero.
66
5.7.1 ‘C’ Code for Sutherland and Cohen Subdivision Line Clipping Algorithm
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<math.h>
#include<graphics.h>
/* Defining structure for nd point of line */
typedef struct coordinate
{
int x, y;
char code [4];
} PT;
void drawwindow ( );
void drawline (PT P1, PT p2, int c1);
PT setcode (PT p);
int visibility (PT p1, PT p2);
PT reserendpt (PT p1, PT p2);
main ( )
{
int gd=DETECT, gm, v;
PT p1, p2, ptemp;
initgraph (&gd, &gm, “ “);
cleardevice ( );
printf (“\n\n\t\tENTER END-POINT 1 (x, y): “);
scanf (“%d, %d”, &p2.x, &p2.y);
cleardevice ( );
drawwindow ( );
getch ( );
drawline (p1, p2, 15);
getc ( );
p1=set code (p1);
p2=set code (p2);
v=visibility (p1, p2);
switch (v)
{
case 0: cleardevice ( ); /* Line completely visible */
drawwindow ( );
break;
case 1: cleardevice ( ); /* Line completely invisible */
drawwnidow ( );
break;
case 2: cleardevice ( ); /* Line partly visible */
67
Computer Graphics
drawwindow ( );
break;
}
getch ( );
closegraph ( );
return (0);
}
/* Function to draw window */
void drawwindow ( )
{
setcolor (RED);
line (150, 100, 450, 100);
line (450, 100, 450, 350);
line (450, 350, 150, 350);
line (150, 350, 150, 100);
}
/* Function to draw line between two points
----------------------------------------------------- */
void drawline (PT p1, PT p2, int c1)
{
setcolor (c1);
line (p1.x, p1.y, p2.x, p2.y);
}
/* Function to set code of the coordinates
-----------------------------------------------------*/
PT setcode (PT p)
{
PT ptemp;
if (p.y<100)
ptemp.code [0] = ′1′; /* TOP */
else
ptemp.code [0] = ′0′;
if (p.y>350)
ptemp.code [1] = ′1′ ; /* BOTTOM */
else
ptemp.code [1] = ′0′;
if (p.x>450)
ptemp.code [2] = ′1′; /* RIGHT */
else
ptemp.code [2] = ′0′;
if (p.x<150) /* LEFT */
ptemp.x=p.x;
ptemp.y=p.y;
return (ptemp);
}
68
int visibility (PT p1, PT p2)
{
int i, flag=0;
for (i = 0; i<4; i++)
{
if ((p1.code[i] ! = ′0′) | | (p2.code[i] ! = ′0′))
flag=1
}
if flag= =0)
return (0);
for (i=0; i<4; i++)
{
if ((p1.code[1] = = p1.code [i]) &&(p1.code[i] = = ′1′))
flag=0;
}
if (flag = =0)
return (1);
return (2);
}
/* Function to find new end points
------------------------------------------*/
PT resetendpt (PT p1, PT p2)
{
PT temp;
int x, y, i;
float m, k;
if (p1.code[3] = = ′1′) /* Cutting LEFT Edge*/
x=150;
if (p1.code[2] = = ′1′) /* Cutting RIGHT Edge */
x=450;
if ((p1.code[3] = = ′1′) | | (p1.code[2] = = ′1′))
{
m=(float) (p2.y-p1.y)/(p2.x-p1.x);
k=(p1.y+(m* (x-p1.x));
temp.y=k;
temp.x=x;
for (i=0; i<4; i++)
if (temp.y<=350&&temp.y>=100)
return (temp);
}
if (p1.code[0] = = ′1′) /* Cutting TOP Edge */
y=100;
if (p1.code[1] = = ′1′) /*Cutting BOTTOM Edge */
y=350;
if ((p1.code[0] = = ′1′) | | (p1.code[1] = = ′1′))
{
m=(float) (p2.y-p1.y) / (p2.x-p1.x);
k=(float) p1.x+(float) (y-p1.y) / m;
temp.x=k;
temp.y=y;
for (i=0; i<4; i++)
temp.code [i]=p1.code[i];
return (temp);
69
Computer Graphics
}
else
return (p1);
}
#include<stdio>
#include<graphics.h>
#include<math.h>
typedef struct
{
float x;
float y;
}PT;
int n;
main ( )
{
int i, j, gd, gm;
70
pt d, p1, p2, p[20], pi1, pp[20];
detectgraph (&gd, &gm);
initgraph (&gd, &gm, “ “);
71
Computer Graphics
{
pp[j].y = p[i].y;
}
pp[j].x = p1.x;\
j++;
pp[j].x=p[i+1].x;
pp[j].y=p[i+1].y;
j++;
}
}
else
pp [j].y = p[i].y;
}
pp[j].x = p1.x;
j++;
}
}
for (i=0l i<j; i++)
{
p[i].x = pp[i].x;
p[i].y = pp[i].y;
n=j;
}
if (p[i+1].x-p[i].x!=0)
72
{
pp[j].y = 9p[i+1].y-p[i].y) / (p[i+1].x-p[i].x)
= (p2.x-p[i].x) + p[i].y;
}
else
{
pp[j].y = p[i].y;
}
pp[j].x = p2.x;
j++;
pp[j].x=p[i+1].x;
pp[j].y+p[i+1].y;
j++;
}
if (p[i].x < p2.x && p[i+1].x <= p2.x)
{
if (p[i+1].x-p[i].x!=0)
{
ppt[j].y = (p[i+1].y-p[i].y) / (p[i+1].x-p[i].x)*
(p2.x-p[i].x)+p[i].y;
}
else
{
pp[j].y = p[i].y;
}
pp[j].x = p2.x;
j++;
}
}
for (i=0; i<j; i++)
{
p[i].x = pp[i].x;
p[i].y = pp[i].y;
}
p[i].x = pp[0].x;
p[i].y = pp[0].y;
n=j;
}
73
Computer Graphics
else
}
pp[j].x = p[i].x;
}
pp[j].y = p1.y;
j++;
pp[j].x=p[i+1].x;
pp[j].y=p[i+1].y;
j++;
}
if (p[i].y > p1.y && p[i+1].y >= p1.y)
{
pp[j].y = p[i+1].y;
pp[j].x = p[i+1].x;
j++;
}
if (p[i].y > p1.y && p[i+1].y <= p1.y)
{
if (p[i+1].y-p[i].y!=0)
{
pp[j].x = (p[i+1].x-p[i].x) / (p[i+1].y-p[i].y)*
(p1.y-p[i].y)+p[i].x;
}
else
{
pp[j].x = p[i].x;
}
pp[j].y = p1.y;
j++;
}
}
for (i=o; i<j; i++)
{
p[i].x = pp[i].x;
p[i].y = pp[i].y;
n=j;
}
bottom (PT p2, PT p[20], PT pp[20])
{
int i, j=0;
for (i=0; i<n; i++)
{
if (p[i].y > p2.y && p[i+1].y <= p2.y)
{
if (p[i+1].y-p[i].y!=0)
{
pp[j].x = (p[i+1].x-p[i].x) / (p[i+1].y-p[i].y)*
(p2.y-p[i].y)+p[i].x;
}
else
{
74
pp[j].x = p[i].x;
}
pp[j].y = p2.y;
j++;
pp[j].x=p[i+1].x;
pp[j].y=p[i+1].y;
j++;
}
if (p[i].y < p2.y && p[i+1].y <= p2.y)
{
pp[j].y = p[i+1].y;
pp[j].x = p[i+1].x;
j++;
}
if (p[i].y < p2.y && p[i+1].y >=p2.y)
{
if (p[i+1].y –p[i].y!=0)
{
pp[j].x = (p[i+1].x-p[i].x) / (p[i+1].y-p[i].y)*
(p2.y-p[i].y)+p[i].x;
}
else
{
pp[j].x =p[i].x;
}
pp[j].y =p2.y;
j++;
}
}
for )i=o; i<j; i++)
{
p[i].x = pp[i].x;
p[i].y = pp[i].y;
}
p[i].x = pp[0].x;
p[i].y = pp[0].y;
n=j;
}
drawpolygon (PT x[20], int n)
{
int i;
for (i=o; i<n-i; i++)
{
line (x[i].x,x[i].y,x[i+1].x,x[i+1].y);
}
line (x[i].x,x[i].y,x[0].x,x[0].y);
}
75
Computer Graphics
Summary
• A graphics package allows us to specify which part of a defined picture is to be displayed and where that part
is to be displayed on the display device.
• The picture is stored in the computer memory using any convenient Cartesian coordinate system, referred to as
world coordinate system (WCS).
• When the picture is displayed on the display device it is measured in physical device coordinate system (PDCS)
corresponding to the display device.
• World coordinate system (WCS) is infinite in extent and the device display area is finite.
• An area on a device to which a window is mapped is called as a viewport.
• As the resolution of the screen increases, the size of the screen in pixels increases.
• The matrix used for this composite transformation is given by, =T∙R
• The transformation of object description from normalised coordinates to device coordinates is called workstation
transformation.
• A Programmer’s Hierarchical Interactive Graphics Standard (PHIGS) is a package which provides functions
for controlling graphical output and input.
• The procedure that identifies the portions of a picture that are either inside or outside of a specified region of
space is referred to as clipping.
• The lines are said to be interior to the clipping window and hence visible, if both end points are interior to the
window.
References
• Computer Graphics and Multimedia. [Pdf] Available at: <http://www.doeacc.edu.in/jsp/question/JULY06/B44-
R3.pdf> [Accessed 19 May 2011].
• Langbein, F. C., CM0304 Graphics. [Pdf] Available at: <http://www.langbein.org/publish/graphics/III/G-13-
III_2-handout.pdf> [Accessed 21 June 2013].
• nptelhrd, 2009. Lecture - 6 Windowing and Clipping, [Video online] Available at: <http://www.youtube.com/
watch?v=f9E8T-eBcbo> [Accessed 21 June 2013].
• nptelhrd, 2008. Lecture - 4 Clipping, [Video online] Available at: <http://www.youtube.com/watch?v=7iYggzuo6Ks>
[Accessed 21 June 2013].
• Desai, Computer Graphics, PHI Learning Pvt. Ltd.
• Chauhan, R. K., Computer Graphics & Multimedia, Galgotia Publications.
Recommended Reading
• Alavala, R. C., Computer Graphics, PHI Learning Pvt. Ltd.
• Pai, S., 2004. Principles of Computer Graphics: Theory and Practice Using OpenGL and Maya, Springer.
• Krishnamurthy, 2002. Introduction To Computer Graphics, Tata McGraw-Hill Education.
76
Self Assessment
1. The process of selecting and viewing the picture with different views is called __________.
a. clipping
b. windowing
c. viewing
d. mapping
2. The picture is stored in the computer memory using any convenient Cartesian coordinate system, referred to
as __________.
a. world coordinate system (WCS)
b. physical device coordinate system (PDCS)
c. windowing
d. clipping
3. Displaying an image of a picture involves __________ the coordinates of the points and lines.
a. clipping
b. windowing
c. mapping
d. viewing
7. What is the transformation which maps the viewing coordinate to normalised device coordinate called?
a. Scaling
b. Translation
c. Normalisation transformation
d. Workstation transformation
77
Computer Graphics
b. =T+R
c. =T*R
d. =T∙R
78
Chapter VI
3-D Transformations
Aim
The aim of this chapter is to:
• explain 3d geometry
• explicate 3d transformations
Objectives
The objectives of this chapter are to:
• explain 3D primitive
• define 3D viewing
Learning outcome
At the end of this chapter, you will be able to:
79
Computer Graphics
6.1 Introduction
Some graphics applications are two-dimensional, such as charts and graphics, certain maps and so on. However, to
create a realistic picture, scene or model we need to represent it in 3-D graphics. The creation of realistic pictures
is an important task in fields such as simulation, design, entertainment, advertising, research, education, command
and control.
To create a realistic picture, we must process the scene or picture through viewing coordinate transformations
and projection routine that transform three-dimensional viewing coordinates onto two-dimensional device
coordinates.
We must identify the visible parts of the scene for a selected view and we must apply the surface rendering algorithm
to create a realistic scene or picture.
= and =
Where ( ) and ( are the two points which specify the line.
A plane is specified by a single equation of the form.
+ + +D=0
80
6.3.2 Algorithm 2: 3-D Relative Move
MOVE_REL_3-D (DX, DY, DZ)
Arguments DX, DY, DZ specify the changes to be made in current pen position
Global DF_CUR_X, DF_CUR_Y, DF_CUR_Z; current pen position coordinates
BEGIN
DF_CUR_X ← DF_CUR_X + DX;
DF_CUR_Y ← DF_CUR_Y + DY;
DF_CUR_Z ← DF_CUR_Z + DZ;
DF_ENTER (1);
RETURN;
END;
81
Computer Graphics
82
6.4.2 Surface Rendering
• Surface rendering involves setting the surface intensity of objects according to the lighting conditions in the
scene and according to assigned surface characteristics.
• The lighting conditions specify the intensity and positions of light sources and the general background illumination
required for a scene.
• On the other hand, the surface characteristics of objects specify the degree of transparency and smoothness or
roughness of the surface.
• Usually, the surface rendering methods are combined with perspective and visible-surface identification to
generate a high degree of realism in a displayed scene.
6.4.5 Shadows
• We can further explain realism by reproducing shadows casted by objects on one another.
• Shadows enhance realism and provide additional depth cues.
6.5.1 Translation
• Three dimensional transformation matrix for translation with homogeneous coordinates is as given below. It
specifies three coordinates with their own translation factor.
T=
=P∙T
83
Computer Graphics
• Like two dimensional transformations, an object is translated in three dimensions by transforming each vertex
of the object.
6.5.2 Scaling
• Three dimensional transformation matrix for scaling with homogeneous coordinates is as given below:
S=
84
=P∙S
• A scaling of an object with respect to a selected fixed position can be represented with the following transformation
sequence:
translate the fixed point to the origin
scale the object
translate the fixed point back to its original position
6.5.3 Rotation
• Unlike the two dimensional rotation, where all transformations are carried out in xy plane, a three dimensional
rotation can be specified around any line in space.
• Therefore, for three dimensional rotations we have to specify an axis of rotation about which the object is to be
rotated along with the angle of rotation.
• The easier rotation axes to handle are those that are parallel to the coordinate axes. It is possible to combine the
coordinate axis rotations to specify any general rotation
6.5.4 Reflection
• A three dimensional reflection can be performed relative to a deflected reflection axis or with respect to a
selected reflection plane.
• The three dimensional reflection matrices are set up similarly to those for two dimensions.
• Reflections relative to a given axis are equivalent to 180° rotations about that axis.
• Reflections with respect to a plane are equivalent to 180° rotations in four dimensional spaces.
85
Computer Graphics
6.7 Projections
After converting the description of objects from world coordinates to viewing coordinates, we can project the three
dimensional objects onto two dimensional view plane. There are two basic ways of projecting objects onto the view
plane:
• Parallel projection
• Perspective projection
• Fig. 6.4 shows that a parallel projection preserves proportions of objects but does not produce the realistic
views.
86
Fig. 6.5 Perspective projection of an object to the view plane
87
Computer Graphics
88
Summary
• Some graphics applications such as charts, graphics, certain maps are two-dimentional. However, to create a
realistic picture, scene or model we need to represent it in 3-D graphics.
• We need additional third axis in 3-D geometry to specify the coordinates of any point.
• The third axis, for depth, is named the z-axis.
• There are two types of three dimensional reference systems according to the orientation for the coordinate axes:
Right handed system and left handed system.
• In 3-D geometry, the line is specified by a pair of equations.
= and =
• To display a view of the object, its description has to be transferred to the camera reference coordinates and
projected onto the selected display plane.
• In parallel projection, z coordinate is discarded and parallel lines from each vertex on the object are extended
until they intersect the view plane.
• The perspective projection on the other hand produces realistic views but does not preserve relative
projections.
• To create realistic image, the depth information is important, so that we can easily identify, for a particular
viewing direction, which is the front and which is the back of displayed objects.
• Surface rendering involves setting the surface intensity of objects according to the lighting conditions in the
scene and according to assigned surface characteristics.
• Stereoscopic devices present two views of a scene: one for the left eye and the other for the right eye.
• A three dimensional reflection can be performed relative to a deflected reflection axis or with respect to a
selected reflection plane.
References
• Mortenson, E. M., 2007. Geometric transformations for 3D modeling, Volume 10, 2nd ed. Industrial Press.
• Chen, X. J. & Chen, C., 2008. Foundations of 3D Graphics Programming: Using JOGL and Java3D, 2nd ed.
Springer.
• 3D TRANSFORMATIONS [Pdf] Available at: <http://web.iitd.ac.in/~hegde/cad/lecture/L6_3dtrans.pdf>
[Accessed 21 June 2013].
• 3D Transformations [Pdf] Available at: <http://comp575.web.unc.edu/files/2010/10/11transforms3d.pdf>
[Accessed 21 June 2013].
• Dr. Chawla, A., Lecture - 9 3D Transformations and Projection [Video online] Available at: <http://www.
youtube.com/watch?v=I8o4kK9QRL4> [Accessed 21 June 2013].
• Lecture - 8 3D Viewing [Video online] Available at: <http://www.youtube.com/watch?v=k2ajK9uM0Co>
[Accessed 21 June 2013].
Recommended Reading
• Lengyel, E., 2004. Mathematics for 3d Game Programming and Computer Graphics, 2nd ed. Cengage
Learning.
• Bhatia, 2008. Computer Graphics, I. K. International Pvt Ltd.
• Blundell, B., 2008. An Introduction to Computer Graphics and Creative 3-D Environments, Springer.
89
Computer Graphics
Self Assessment
1. In ________, z coordinate is discarded and parallel lines from each vertex on the object are extended until they
intersect the view plane.
a. perspective projection
b. parallel projection
c. orthographic projection
d. oblique projection
6. What produces realistic views but does not preserve relative projections?
a. Orthographic projection
b. Oblique projections
c. Perspective projection
d. Parallel projection
90
7. Which of the following statements is false?
a. To create realistic image, the depth information is important so that we can easily identify, for a particular
viewing direction, which is the front and which is the back of displayed objects.
b. The depth of an object can be represented by the intensity of the image.
c. For the cavalier projection, the direction of projection makes a 45° angle with the view plane.
d. For the cavalier projection, the direction of projection makes a 90° angle with the view plane.
8. The ___________ characteristics of objects specify the degree of transparency and smoothness or roughness
of the surface.
a. surface
b. reflection
c. shadow
d. depth cue
9. The parts of the objects closest to the viewing position are displayed with highest intensities, and objects farther
away are displayed with decreasing intensities. What is this effect known as?
a. depth cueing
b. perspective projection
c. parallel projection
d. oblique projection
= and =
a.
= and =
b.
= and =
c.
= and =
d.
91
Computer Graphics
Chapter VII
Hidden Surfaces and Lines
Aim
The aim of this chapter is to:
Objectives
The objectives of this chapter are to:
Learning outcome
At the end of this chapter, you will be able to:
• describe the Pseudo code for building a binary space partition tree
92
7.1 Introduction
In a given set of 3D objects and viewing specification, we wish to determine which lines or surfaces of the objects
are visible, so that we can display only the visible lines or surfaces. This process is known as hidden surfaces or
hidden line elimination, or visible surface determination. The hidden line or hidden surfaces or algorithm determines
the lines, edges, surfaces or volumes, which are visible or invisible to an observer at a specific point in space. These
algorithms are broadly classified according to whether they deal with object definitions directly or with their projected
images. These two approaches are called object-space methods and image-space method, respectively.
93
Computer Graphics
7.2.1 Advantages
• It is easy to implement.
• It can be implemented in hardware to overcome the speed problem.
• Since the algorithm processes objects one at a time, the total number of polygons in a picture can be arbitrary
large.
7.2.2 Disadvantages
• It requires an additional buffer and hence the large memory.
• It is a time consuming process, as it requires comparison for each pixel instead of for the entire polygon.
94
Overlapping or intersecting polygon – one that is partly inside and partly outside the area.
• If all the polygons are disjoint from the area, then the background colour is displayed in that area.
• If there is only one intersecting or only one contained polygon, then the area is first filled with the background
colour, and then the part of the polygon contained in the area is filled with colour of polygon.
• If there is a single surrounding polygon, but no intersecting or contained polygons, then the area is filled with
the colour of the surrounding polygon.
• If there are more than one polygons intersecting, contained in, or surrounding the area then we have to do some
more processing.
95
Computer Graphics
7.4.1 Advantages
• It follows the divide-and-conquer strategy; therefore, parallel computers can be used to speed up the process.
• Extra memory buffer is not required.
96
7.6.1 The Pseudo Code for Building a BSP Tree
struct
{
polygon root;
polygon root;
BSP_Tree = NULL;
else
{ root = selectpolygon (&polyList);
backlist = NULL;
frontList = NULL;
else
{ Sliptpolygon (P, root, &frontPart, &backPart);
AddtoBSPList (frontPart, &frontList);
AddtoBSPList (backPart, &backlist);
}
endif
}
return combineBSP_tree (BSP_makeTree {frntList), root, BSP_makeTree (backlist);
}
} / * BSP_makeTree */
97
Computer Graphics
else
endif
}
endif
} /* DisplayBSP_Tree */
98
Summary
• A scan line method of hidden surface removal is another approach of image space method.
• The hidden line or hidden surfaces or algorithm determines the lines, edges, surfaces or volumes, which are
visible or invisible to an observer at a specific point in space.
• Object-Space method is implemented in the physical coordinate system in which objects are described.
• Image space method is implemented in the screen coordinate system in which the objects are viewed.
• Z-buffer algorithm is one of the simplest and commonly used image space approaches to eliminate hidden
surfaces.
• Surrounding polygon is the one that completely encloses the (shade) area of interest.
• Overlapping or intersecting polygon is the one that is partly inside and partly outside the area.
• Inside or Contained polygon is the one that is completely inside the area.
• Outside or Disjoint polygon is the one that is completely outside the area.
• To find how objects hide the lines, it is necessary to compare lines with relevant edges of the objects i.e., it is
not necessary to compare each line against all of the polygon edges in an object in order to find how objects
hide the lines.
• The edge for which, both the polygons represent front face and other represents back face is called contour
edge.
• The edge for which, both the polygons represent front faces or back faces is called interior edge.
• The binary space partitioning (BSP) tree visible surface algorithm assumes that for a given viewpoint a polygon
is correctly rendered, if all the polygons on its side away from the viewpoint are rendered first; then the polygon
itself is rendered; and finally, all the polygons on the side near the viewport are rendered.
References
• Kuijk, A. M. & Straber, W., 1998. Advances in Computer Graphics Hardware II, Springer.
• Pachghare, V. K., 2005. Comprehensive Computer Graphics: Including C++, Laxmi Publications.
• Hidden Surface and Hidden Line Removal [Pdf] Available at: <http://www.ece.ubc.ca/~saifz/eece478/course/
hidden.pdf> [Accessed 21 June 2013].
• Krishnan, S. & Manocha, D., Hidden Surface Removal Algorithms for Curved Surfaces [Pdf] Available at:
<https://wwwx.cs.unc.edu/~geom/papers/documents/technicalreports/tr94063.pdf> [Accessed 21 June 2013].
• Dr. Chawla, A., Lecture - 13 Hidden Surface Removal [Video online] Available at: <http://www.youtube.com/
watch?v=W6d1jsJIrck> [Accessed 21 June 2013].
• Dr. Chawla, A., Lecture - 12 Hidden Surface Removal [Video online] Available at: <http://www.youtube.com/
watch?v=GxSCRLF37z4> [Accessed 21 June 2013].
Recommended Reading
• Ryan, D., 2011. History of Computer Graphics: DLR Associates Series, AuthorHouse.
• Sinha & Udai, 2008. Computer Graphics, Tata McGraw-Hill Education.
• Angel, E., 2008. Interactive Computer Graphics: A Top-Down Approach Using Opengl, 5/E, 5th ed. Pearson
Education India
99
Computer Graphics
Self Assessment
1. _____________ is implemented in the physical coordinate system in which objects are described.
a. Image space method
b. Object space method
c. Z-buffer algorithm
d. Scan line algorithm
2. ___________ is implemented in the screen coordinate system in which the objects are viewed.
a. Scan line algorithm
b. Object space method
c. Image space method
d. Z-buffer
3. __________ is one of the simplest and commonly used image space approaches to eliminate hidden surfaces.
a. Z-buffer algorithm
b. Scan line algorithm
c. DDA algorithm
d. Bresenham’s algorithm
100
8. Which of the following statements is false?
a. The edge for which both the polygons represent front face and other represents back face is called contour
edge.
b. The edge for which both the polygons represent front faces or back faces is called binary tree.
c. The objects within the image may not hide the line or may hide it partly or completely.
d. The edge for which both the polygons represent front faces or back faces is called interior edge.
10. Which algorithm uses the polygons in the scene as the separation dividing plane.
Polygons that intersect the separating plane are split along the separating plane, and each portion is placed in
the appropriate half space.
a. BSP algorithm
b. Scan line algorithm
c. Z-buffer algorithm
d. Subdivision algorithm
101
Computer Graphics
Chapter VIII
Light, Colour and Shading
Aim
The aim of this chapter is to:
Objectives
The objectives of this chapter are to:
• define ray-tracing
Learning outcome
At the end of this chapter, you will be able to:
• define gloss
102
8.1 Introduction
The shading model is used to calculate the intensity of light that we should see at a given point on the surface of an
object. The shading model is also called illumination model or lighting model.
103
Computer Graphics
8.5 Transparency
• A transparent surface, in general, produces both, reflected and transmitted light.
• It has a transparency coefficient T as well as values for reflectivity and specular reflection.
• The coefficient of transparency depends on the thickness of the object because the transmission of light
exponentially on the distance which the light ray must travel within the object.
• The expression for coefficient of transparency is given as,
T=
Where,
T = the coefficient of property of material which determines how much of the light is transmitted at the
surface instead of reflected.
a = the coefficient property of a material which tells how quickly the material absorbs or attenuates the
light.
d = the distance light must travel in the object.
• When the light crosses the boundary between two media it changes the direction. This effect is called
refraction.
• The effect of refraction is observed because the speed of light in different materials resulting different path for
refracted light for that of incident light.
• The direction of refracted light is specified by the angle of refraction ).
• It is the function of the property materials called the index of refraction (n).
• The angle of refraction , is calculated from the angle of incident , the index of refraction of the incident
material and the index of refraction of the refracting material according to Snell’s law,
Sin = sin
8.6 Shadows
• A shadowed object is one which is hidden from the light source.
• It is possible to use hidden surface algorithms to locate the areas where light sources produce shadows.
• In order to achieve this we have to repeat the hidden surface calculation using light source as the viewport.
• This calculation divides the surfaces into shadowed and unshadowed groups.
• The surfaces that are visible from the light source are not in shadow; those that are not visible from the light
source are in shadow.
• Surfaces which are visible and which are also visible from the light source are shown with both, the background
illumination and the light source illumination.
• Surfaces which are visible, but which are hidden from the light source are displayed with only the background
illumination.
• Another way to locate shadow areas is the use of shadow volumes.
• The shadow volume is defined by the light source and an object and is bounded by a set of visible shadow
polygons. This volume is also known as polygon’s shadow volume.
104
8.7 Ray-Tracing
• If we consider the line of sight from a pixel position on the view plane through a scene, we can determine which
objects in the scene intersect this line.
• From the intersection points with different object, we can identify the visible surface as the one whose intersection
point is closest to the pixel. Ray tracing is an extension of this basic idea.
8.7.1 Gloss
• Traditional ray tracing is good at representing perfect reflecting surfaces, but poor at representing glossy or
partially reflecting surfaces.
• Only when surfaces are perfect, mirrors do the reflections which look identical to the scene they are
reflecting.
• More often surfaces are glossy and reflect a blurred image of the scene. This is due to the light scattering
properties of the surface.
• Reflections in traditional ray tracing are always sharp, even partial reflections.
• Glossy surfaces are generated in distributed ray tracing by randomly distributing rays reflected by a surface.
• Instead of casting a single ray out in the reflecting direction, a packet of rays are set out around the reflecting
direction.
• The actual value of reflectance can be found by taking the statistical mean of the values returned by each of
these rays.
8.7.2 Translucency
• Traditional ray tracing is good at representing perfectly transparent surfaces, but poor at representing translucent
surfaces.
• Real surfaces that are translucent generally transmit a blurred image of the scene behind them.
• Distributed ray tracing achieves these types of translucent surface by casting randomly distributed rays in the
general direction of the transmitted ray from traditional ray tracing.
• The value computed from each of these rays is then averaged to form the true translucent component.
105
Computer Graphics
106
Fig. 8.1 Colour table
107
Computer Graphics
Summary
• The shading model is used to calculate the intensity of light that we should see at a given point on the surface
of an object. The shading model is also called illumination model or lighting model.
• An objects illumination is as important as its surface properties, in computing its intensity.
• When we illuminate a shiny surface such as polished metal or an apple with a bright light, we observe highlight
or bright spot on the shiny surface. This phenomenon of reflection of incident light in a concentrated region
around the specular reflection angle is called specular reflection.
• We can shade any surface by calculating the surface normal at each visible point and applying the desired
illumination model at that point.
• The fast and simplest method for shading polygon is constant shading, also known as faceted shading or flat
shading.
• A transparent surface, in general, produces both, reflected and transmitted light.
• The expression for coefficient of transparency is given as, T =
• A shadowed object is one which is hidden from the light source.
• Glossy surfaces are generated in distributed ray tracing by randomly distributing rays reflected by a surface.
• Shadows in the real world are much softer.
• Both, the human eye and cameras have a finite lens aperture, and therefore have a finite depth of field.
• If objects in the scene are in motion relative to the cameras, then they will appear blurred on the film.
• Colour tables have 8-bit of control over each of the red, green and blue channels. Therefore, they can have 256
intensity levels.
• A colour table allows us to map between a colour index in the frame buffer and a colour specification.
• The ratio of the light reflected from the surface to the total incoming light to the surface is called coefficient of
reflection or the reflectivity.
References
• Alavala, R. C., Computer Graphics, PHI Learning Pvt. Ltd.
• Buss, R. S., 2003. 3D Computer Graphics: A Mathematical Introduction with OpenGL, Cambridge University
Press.
• Tutorial 7 – Computer Graphics CSC418/2504 Illumination, Shading, and Colour [Pdf] Available at: <http://
www.dgp.toronto.edu/~patrick/csc418/notes/tutorial7.pdf> [Accessed 21 June 2013].
• Schulze, P. J., Introduction to Computer Graphics Lecture #7: Color and Shading [Pdf] Available at: < http://
ivl.calit2.net/wiki/images/d/d1/07_Shaders.pdf> [Accessed 21 June 2013].
• Computer Graphics - Lecture 6 [Video online] Available at: <http://www.youtube.com/watch?v=ONmbLohlsUA>
[Accessed 21 June 2013].
• Computer Graphics 2012, Lect. 3(2) - Curves, Surfaces, and Shading [Video online] Available at: <http://www.
youtube.com/watch?v=fv8BwhInCks> [Accessed 21 June 2013].
Recommended Reading
• Pakhira, K. M., 2010. Computer Graphics, Multimedia and Animation, 2nd ed. PHI Learning Pvt. Ltd.
• Rost, J. R., Licea-Kane, M. B., Ginsburg, D., Kessenich, M. J., Lichtenbelt, B., Malan, H. & Weiblen, M., 2009.
OpenGL Shading Language, 3rd ed. Pearson Education.
• McConnell, J. J., 2006. Computer Graphics: Theory Into Practice, Jones & Bartlett Learning
108
Self Assessment
1. An object’s _________ is as important as its surface properties in computing its intensity.
a. shadow
b. lighting
c. illumination
d. reflection
3. Due to ________ at the highlight, the surface appears to be in its original colour, but the colour of incident
light is white.
a. specular reflection
b. coefficient of reflection
c. reflectivity
d. shadow
6. Real surfaces that are _________ generally transmit a blurred image of the scene behind them.
a. transparent
b. translucent
c. opaque
d. white in colour
109
Computer Graphics
8. What is the fastest and simplest method for shading polygon known as?
a. shading
b. lighting
c. faceted shading
d. reflectivity
b. Sin = sin
c. Sin = sin
d. Sin = sin
110
Chapter IX
Curves, Fractals and Animation
Aim
The aim of this chapter is to:
• explain curve
• discuss fractals
• explain interpolation
Objectives
The objectives of this chapter are to:
Learning outcome
At the end of this chapter, you will be able to:
111
Computer Graphics
9.1 Introduction
The only primitive in geometric objects that computer graphics hardware typically can draw are points, lines
and polygons. Usually, there are special mechanisms to draw images, text characters but these are not commonly
considered ‘geometric’ since they are not usually transformed by geometric operations like rotation and perspective
projection. Obviously it is important that graphics programs be able to draw more complex geometric forms from
simple circles to complex surfaces in three dimensions. We can use two approaches to draw curved lines. One
approach is to use a curve generation algorithm such as DDA. In this approach, a true curve is created. A major
problem in the design of graphics libraries is to provide a high level interface to the hardware that allows users to
draw curves and surfaces to line segments and polygons themselves.
9.2 Interpolation
• We have to deal with some complex curves for which no direct mathematical function is available. Such curves
can be drawn using approximation methods.
• If we have set of sample points which lie on the required curves, then we can draw the required curve by filling
portions of curves with the pieces of known curves which pass through nearby sample points.
• The gap between the sample points can be filled by finding the coordinates of the points along the known
approximating curve and connecting these points with line segments.
112
Fig. 9.1 The interpolation process
• The main task in this process is to find the suitable mathematical expression for the known curve.
• There are polynomials, trigonometric, exponential and other classes of functions that can be used to approximate
the curve.
• Usually polynomial functions in the parametric forms are preferred.
• The polynomial functions in the parametric form can be given as:
x = (u)
y = (u)
z = (u)
113
Computer Graphics
114
9.4.1 Properties of Bezier Curve
• The basic functions are real.
• Bezier curve always passes through the first and last control points, i.e., curve has same end points as the guiding
polygon.
• The degree of the polynomials defining the curve segment is one less than the number of defining polygon point.
Therefore, for 4 control points, the degree of the polynomial is three, i.e. cubic polynomial.
• The curve generally follows the shape of the defining polygon.
• The direction of the tangent vector at the end points is the same as that of the vector determined by first and
last segments.
• The curve lies entirely within the convex hull formed that the polynomial smoothly follows the control
points.
• The curve exhibits the variation diminishing property. This means that the curve does not oscillate about any
straight line defining polygon.
• The curve is invariant under an affine transformation.
115
Computer Graphics
9.6 Fractals
In nature we come across rough, jagged, random surfaces and edges when we try to draw mountains, trees, rivers,
etc. Such rough, jagged and random surfaces are called fractals.
• Add an offset to the midpoint in such a way that the resultant midpoint should not lie on the line. This can be
achieved by adding offset term to each coordinate as follows,
116
= L x W x GAUSS
= L x W X GAUSS
Where,
L : Length of the segment
W : waiting function governing the curve roughness (i.e. fractal dimension)
GAUSS : Gaussian variable which returns random values between -1 and 1 with 0 mean i.e., returned values consist
of equal amount of positive and negative values.
• The shifted midpoint divides the original line into two parts. Repeat the same process for each part
separately.
• Repeat the processes until the segments become small enough. By following the above procedures we can get
fractal line as below:
117
Computer Graphics
Summary
• To specify a curve, we need more information than just its endpoints.
• The curve generation algorithms for curves other than circular or elliptical such as airplane wings or cars or
human faces, are complex.
• If we have a set of sample points which lie on the required curves, then we can draw the required curve by filling
portions of curves with the pieces of known curves which pass through nearby sample points.
• To produce a smooth curve through a designated set of points, a flexible strip called spline is used.
• Bezier curve is another approach for the construction of the curve.
• The degree of the polynomials defining the curve segment is one less than the number of defining polygon point.
Therefore, for 4 control points the degree of the polynomial is three, i.e., cubic polynomial.
• A curve generated by using the vertices of a defining polygon dependeds on some interpolation or approximation
scheme to establish the relationship between the curve and the polygon.
• Self similar fractals have parts those are scaled-down versions of the entire object.
• Self affine fractals have parts those are formed with different scaling parameters, , , in different coordinate
directions.
• In invarient fractals, non-linear transformation is used.
• The concept of fractal lines can be extended to generate fractal surfaces.
References
• Stevens, T. R., 2002. Computer Graphics Dictionary, Cengage Learning.
• Pakhira, K. M., 2010. Computer Graphics, Multimedia and Animation, 2nd ed. PHI Learning Pvt. Ltd.
• Demko, S., Construction of Fractal Objects [Pdf] Available at: <http://www-users.cs.umn.edu/~bstanton/pdf/
p271-demko.pdf> [Accessed 21 June 2013].
• Irving, G. & Segerman, H., Developing fractal curves [Pdf] Available at: <http://www.ms.unimelb.edu.
au/~segerman/papers/developing_fractal_curves.pdf> [Accessed 21 June 2013].
• Lecture-2 Raster Graphics [Video online] Available at: <http://www.youtube.com/watch?v=fWaEClGVJaI&l
ist=PL112A527F83F7A5E4> [Accessed 21 June 2013].
• Lecture - 32 Fractals (Contd.) [Video online] Available at: <http://www.youtube.com/watch?v=1r4ewtqgBAE>
[Accessed 21 June 2013].
Recommended Reading
• Zobrist, W. G. & Sabharwal, C., 1992. Progress in Computer Graphics, Volume 1, Intellect Books.
• Gross, M. & Pfister, H., 2011. Point-Based Graphics, Morgan Kaufmann.
• Deussen, O. & Lintermann, B., 2005. Digital Design of Nature: Computer Generated Plants and Organics,
Springer
118
Self Assessment
1. When polynomial sections are fitted for a curve to pass through all control points, the resulting ________ is
said to interpolate the set of control points.
a. curve
b. point
c. polygon
d. vector
2. _________ always passes through the first and last control points, i.e., curve has same end points as the guiding
polygon.
a. B-spline
b. Cuve
c. Spline
d. Bezier curve
119
Computer Graphics
8. The sum of the B-spline basis functions for any parameter value (u) is _________.
a. 2
b. 3
c. 1
d. 5
9. __________ have parts those are scaled-down versions of the entire object.
a. Curves
b. Fractals
c. Polygons
d. Vectors
10. Which of the following concepts can be extended to generate fractal surfaces?
a. Fractal lines
b. Lines
c. Curves
d. Polygons
120
Application I
Obtain transformation matrix for rotation about the line joining the points (0, 0, 0) and (1, 1, 1) with the angle of
rotation 45°in counter-clockwise sense.
Solution:
In this case, the line passes through the origin, so the translation is not required. Therefore, can be given as,
= ∙R∙
By usual notations,
=
|V| =
Here, a = 1, b = 1, c = 1.
= , R=
∙R∙
121
Computer Graphics
Application II
Construct a B-spline curve of order 4 and with 4 polygon vertices A(1, 1), B(2, 3), C(4, 3) and D(6, 2).
Application III
Find the transformation for:
a. Cavalier projection with θ = 45°
b. Cabinet projection with θ = 30°
122
Bibliography
References
• 3D Transformations [Pdf] Available at: <http://comp575.web.unc.edu/files/2010/10/11transforms3d.pdf>
[Accessed 21 June 2013].
• 3D TRANSFORMATIONS [Pdf] Available at: <http://web.iitd.ac.in/~hegde/cad/lecture/L6_3dtrans.pdf>
[Accessed 21 June 2013].
• Alavala, R. C., Computer Graphics, PHI Learning Pvt. Ltd.
• Bandukwala, F., Introduction to Computer Graphics, [Pdf] Available at: <http://cseweb.ucsd.edu/classes/wi03/
cse167/lectures/lec2.pdf> [Accessed 21 June 2013].
• Barfield, A., 2010. Class: CSC 370: Computer Graphics, [Video online] Available at: <http://www.youtube.
com/watch?v=fKz87vfz4E0> [Accessed 21 June 2013].
• Buss, R. S., 2003. 3D Computer Graphics: A Mathematical Introduction with OpenGL, Cambridge University
Press.
• Chauhan, R. K., Computer Graphics & Multimedia, Galgotia Publications.
• Chen, X. J. & Chen, C., 2008. Foundations of 3D Graphics Programming: Using JOGL and Java3D, 2nd ed.
Springer.
• Computer Graphics - Lecture 6 [Video online] Available at: <http://www.youtube.com/watch?v=ONmbLohlsUA>
[Accessed 21 June 2013].
• Computer Graphics 2012, Lect. 3(2) - Curves, Surfaces, and Shading [Video online] Available at: <http://www.
youtube.com/watch?v=fv8BwhInCks> [Accessed 21 June 2013].
• Computer Graphics and Multimedia. Available at: <http://www.doeacc.edu.in/jsp/question/JULY06/B44-R3.
pdf> [Accessed 19 May 2011].
• Computer Graphics, [Pdf] Available at: <http://www.cs.arizona.edu/classes/cs433/spring12/ScanC.prn.pdf>
[Accessed 21 June 2013].
• Demko, S., Construction of Fractal Objects [Pdf] Available at: <http://www-users.cs.umn.edu/~bstanton/pdf/
p271-demko.pdf> [Accessed 21 June 2013].
• Desai, A. A., 2008. Computer Graphics, PHI Learning Pvt. Ltd
• Dr. Chawla, A., Lecture - 12 Hidden Surface Removal [Video online] Available at: <http://www.youtube.com/
watch?v=GxSCRLF37z4> [Accessed 21 June 2013].
• Dr. Chawla, A., Lecture - 13 Hidden Surface Removal [Video online] Available at: <http://www.youtube.com/
watch?v=W6d1jsJIrck> [Accessed 21 June 2013].
• Dr. Chawla, A., Lecture - 9 3D Transformations and Projection [Video online] Available at: <http://www.
youtube.com/watch?v=I8o4kK9QRL4> [Accessed 21 June 2013].
• Foley, J. D., 1995. Computer graphics – Principles and Practice, 2nd ed., Addison-Wesley Publishing Company,
Inc.
• GuerrillaCG, 2008. The Polygon, [Video online] Available at: <http://www.youtube.com/watch?v=-bZ7gstIWyI>
[Accessed 21 June 2013].
• Guha, S., 2011. Computer Graphics Through OpenGL: From Theory to Experiments, CRC Press.
• Hidden Surface and Hidden Line Removal [Pdf] Available at: <http://www.ece.ubc.ca/~saifz/eece478/course/
hidden.pdf> [Accessed 21 June 2013].
• Introduction to Computer Graphics. [Online] Available at: <http://train-srv.manipalu.com/wpress/?p=75678>
[Accessed 19 May 2011].
• Irving, G. & Segerman, H., Developing fractal curves [Pdf] Available at: <http://www.ms.unimelb.edu.
au/~segerman/papers/developing_fractal_curves.pdf> [Accessed 21 June 2013].
• Jarina, V., 2008. Troll2D Primitives/Graphics Test, [Video online] Available at: <http://www.youtube.com/
watch?v=Gh9_6W8BSJw> [Accessed 21 June 2013].
123
Computer Graphics
• Klawonn, F., 2012. Introduction to Computer Graphics: Using Java 2D and 3D, 2nd ed., Springer.
• Krishnan, S. & Manocha, D., Hidden Surface Removal Algorithms for Curved Surfaces [Pdf] Available at:
<https://wwwx.cs.unc.edu/~geom/papers/documents/technicalreports/tr94063.pdf> [Accessed 21 June 2013].
• Kuijk, A. M. & Straber, W., 1998. Advances in Computer Graphics Hardware II, Springer.
• Langbein, F. C., CM0304 Graphics, [Pdf] Available at: <http://www.langbein.org/publish/graphics/III/G-13-
III_2-handout.pdf> [Accessed 21 June 2013].
• Lecture - 32 Fractals (Contd.) [Video online] Available at: <http://www.youtube.com/watch?v=1r4ewtqgBAE>
[Accessed 21 June 2013].
• Lecture - 8 3D Viewing [Video online] Available at: <http://www.youtube.com/watch?v=k2ajK9uM0Co>
[Accessed 21 June 2013].
• Lecture - 8 3D Viewing [Video online] Available at: <http://www.youtube.com/watch?v=k2ajK9uM0Co>
[Accessed 21 June 2013].
• Lecture-2 Raster Graphics [Video online] Available at: <http://www.youtube.com/watch?v=fWaEClGVJaI&l
ist=PL112A527F83F7A5E4> [Accessed 21 June 2013].
• Mortenson, E. M., 2007. Geometric transformations for 3D modeling, Volume 10, 2nd ed. Industrial Press.
• NoyoNLighten, 2012. Computer Graphics- 2D Transformations- I, [Video online] Available at: <http://www.
youtube.com/watch?v=vBKX_bnQDdw> [Accessed 21 June 2013].
• nptelhrd, 2008. Lecture - 1 Introduction to computer graphics, [Video online] Available at: <http://www.youtube.
com/watch?v=fwzYuhduME4&list=PL338D19C40D6D1732> [Accessed 21 June 2013].
• nptelhrd, 2008. Lecture - 4 Clipping, [Video online] Available at: <http://www.youtube.com/watch?v=7iYggzuo6Ks>
[Accessed 21 June 2013].
• nptelhrd, 2008. Lecture -5 Polygon Clipping and Polygon Scan Conversion, [Video online] Available at: <http://
www.youtube.com/watch?v=lZJI_Fth66A> [Accessed 21 June 2013].
• nptelhrd, 2009. Lecture - 6 Windowing and Clipping, [Video online] Available at: <http://www.youtube.com/
watch?v=f9E8T-eBcbo> [Accessed 21 June 2013].
• nptelhrd, 2009. Lecture - 8 2D Transformations, [Video online] Available at: <http://www.youtube.com/
watch?v=iWxS2zpaRjk> [Accessed 21 June 2013].
• Oresoft LWC, 2010. Introduction To Computer Graphics Part 1, [Video online] Available at: <http://www.
youtube.com/watch?v=zyM0xvpzg9c> [Accessed 21 June 2013].
• Pachghare, V. K., 2005. Comprehensive Computer Graphics: Including C++, Laxmi Publications.
• Pakhira, K. M., 2010. Computer Graphics, Multimedia and Animation, 2nd ed. PHI Learning Pvt. Ltd.
• Polygon Filling,[Online] Available at: <http://www.cs.uic.edu/~jbell/CourseNotes/ComputerGraphics/
PolygonFilling.html> [Accessed 21 June 2013].
• Schulze, P. J., Introduction to Computer Graphics Lecture #7: Color and Shading [Pdf] Available at: < http://
ivl.calit2.net/wiki/images/d/d1/07_Shaders.pdf> [Accessed 21 June 2013].
• Shirley, P., 2009. Fundamentals of Computer Graphics. 3rd ed., A K Peters.
• Shoaff, W., 2002. Graphics Primitives, [Pdf] Available at: <http://cs.fit.edu/~wds/classes/prog-graphics/Lectures/
primitives.pdf> [Accessed 21 June 2013].
• Stevens, T. R., 2002. Computer Graphics Dictionary, Cengage Learning.
• Transformation and Projection, [Pdf] Available at: <http://www.magix.in/pdfs/bca3/Notes/cg/chapter3.pdf>
[Accessed 19 June 2013].
• Transformations in 2 Dimensions , [Online] Available at: <http://www.cs.uic.edu/~jbell/CourseNotes/
ComputerGraphics/2DTransforms.html> [Accessed 21 June 2013].
• Tutorial 7 – Computer Graphics CSC418/2504 Illumination, Shading, and Colour [Pdf] Available at: <http://
www.dgp.toronto.edu/~patrick/csc418/notes/tutorial7.pdf> [Accessed 21 June 2013].
124
• UNIT 2 GRAPHIC PRIMITIVES, [Pdf] Available at: <http://vedyadhara.ignou.ac.in/wiki/images/f/f6/B1U2mcs-
053.pdf> [Accessed 21 June 2013].
• Xiang, Z., 2000. Schaum’s Outline of Computer Graphics. 2nd ed., McGraw-Hill.
Recommended Reading
• Akenine-Moller, T., 2008. Real-Time Rendering. 3rd ed., A K Peters/CRC Press.
• Alavala, C. R., 2009. Computer Graphics, PHI Learning Pvt. Ltd.
• Angel, E., 2008. Interactive Computer Graphics: A Top-Down Approach Using Opengl, 5/E, 5th ed. Pearson
Education India.
• Bhatia, 2008. Computer Graphics, I. K. International Pvt Ltd.
• Blundell, B., 2008. An Introduction to Computer Graphics and Creative 3-D Environments, Springer
• Deussen, O. & Lintermann, B., 2005. Digital Design of Nature: Computer Generated Plants and Organics,
Springer.
• Godse, A. P., 2008. Computer Graphics. 4th ed. Technical Publication.
• Govil, S., 2004. Principles of Computer Graphics: Theory and Practice Using OpenGL and Mayaо,
Springer.
• Gross, M. & Pfister, H., 2011. Point-Based Graphics, Morgan Kaufmann.
• Jones, H., 2001. Computer Graphics.: Through Key Mathematics, Springer.
• Krishnamurthy, 2002. Introduction To Computer Graphics, Tata McGraw-Hill Education.
• Lengyel, E., 2004. Mathematics for 3d Game Programming and Computer Graphics, 2nd ed. Cengage
Learning.
• McConnell,J. J., 2006. Computer Graphics: Theory Into Practice, Jones & Bartlett Learning.
• Mukherjee, D. P., 2004. Fundamentals Of Computer Graphics And Multimedia, PHI Learning Pvt
• Pai, S., 2004. Principles of Computer Graphics: Theory and Practice Using OpenGL and Maya, Springer.
• Pakhira, K. M., 2010. Computer Graphics, Multimedia and Animation, 2nd ed. PHI Learning Pvt. Ltd.
• Paquette, A., 2008. Computer Graphics for Artist: An Introduction. 1st ed., Springer.
• Parent, R., October 11, 2007. Computer Animation: Algorithms and Techniques. 2nd ed., Morgan Kaufmann.
• Rost, J. R., Licea-Kane, M. B., Ginsburg, D., Kessenich, M. J., Lichtenbelt, B., Malan, H. & Weiblen, M., 2009.
OpenGL Shading Language, 3rd ed. Pearson Education.
• Ryan, D., 2011. History of Computer Graphics: DLR Associates Series, AuthorHouse.
• Sinha & Udai, 2008. Computer Graphics, Tata McGraw-Hill Education.
• Watt, A., 1999. 3D Computer Graphics. 3rd ed., Addison Wesley.
• Xiang, Z., September 8, 2000. Schaum’s Outline of Computer Graphics. 2nd ed., McGraw-Hill.
• Zobrist, W. G. & Sabharwal, C., 1992. Progress in Computer Graphics, Volume 1, Intellect Books.
125
Computer Graphics
Chapter II
1. a
2. b
3. a
4. d
5. b
6. c
7. a
8. b
9. b
10. d
Chapter III
1. a
2. d
3. c
4. a
5. b
6. a
7. c
8. d
9. a
10. b
126
Chapter IV
1. b
2. a
3. c
4. d
5. a
6. c
7. b
8. a
9. c
10. b
Chapter V
1. b
2. a
3. c
4. d
5. a
6. b
7. c
8. d
9. a
10. c
Chapter VI
1. b
2. d
3. c
4. a
5. b
6. d
7. d
8. a
9. a
10. c
127
Computer Graphics
Chapter VII
1. b
2. c
3. a
4. b
5. d
6. a
7. d
8. b
9. d
10. a
Chapter VIII
1. c
2. b
3. a
4. d
5. a
6. b
7. d
8. c
9. a
10. c
Chapter IX
1. a
2. d
3. a
4. a
5. d
6. c
7. a
8. c
9. b
10. a
128