0% found this document useful (0 votes)
1K views66 pages

CG Unit 1 Tech-Neo

Uploaded by

Aryan Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views66 pages

CG Unit 1 Tech-Neo

Uploaded by

Aryan Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

4A

Important
Sem
SPPU MCQ's

(Compulsory Subject:214453)

COMPUTER GRAPHICS

Sanjesh S. Pawal
Miewera Unveraly, Punel

.
Whh Solved Latest
UNIVERSTY QUISTION PAPII
P4-28A
ECH-NEO
PUBLICATIONS yllabus based MCQs most usetul
for ONLINE & COMPITITME DXAMS.
Whew Athors hspiu hunovalion

Sachin Shah Venture REE DOWNLOAD


A Sample chapterfro Price 385/-
www.techneobooks.in our Android App.
[email protected]
,
Computer Graphics
(Code214453)
Semester IV -Information
Technology
Savitibai Phule Pune
University, Pune (SPPU)

Strictly as per the New Credit System Syllabus SE (Information Technology)


2019 Course
(With Effectfrom Academic Year 2020-21)

Prof. Sanjesh S. Pawale


M.E. (CSE-I.T.)
Assistant Professor,

Department of Computer Engineering


Vishwakarma University

Pune.
Maharashtra, India

LECHNEO
PUBLICATIONS
huovalion
P4-28

Where Authors nspre


A Sachin Shah Venture
Syllabus
Savitribai Phule Pune Pune
University,
Second Year Information Technology (2019 Course)
214453 Computer
Graphics
Teaching Scheme Credits Examination Schemeand Marks
Theory (TH): 03 Hours/Week
Mid_Semester

End Semester
Courses, :Basic Geometry, Trigonometry, Vectors and Matrices, Data Structures and Algorithms
Prerequisite if any

Course Objectives

Understand the foundations of computer graphics: hardware math basis, light and color.
systems,

Understand the complexities of modeling realistic objects throughmodeling complex scenes using a high-level scene

description language.

3. Become acquainted with some advanced topics in computer graphics. The student should gain an expanded vocabulary
for discussing issues relevant to computer graphics (including both the underlying mathematics and the actual

programming).
The student should gain an appreciation and understanding of the hardware and software utilized in constructing

computer graphics applications.

5. The student should gain a comprehension of windows, clipping and view-ports in relation to images displayed on

Screen.

The student should gain an understanding of geometric, mathematicaland algorithmic concepts necessary for

programming computer graphics.

Course Outcomes:
On completion ofthe course, students will be able to-

cO1: and for developingelementary graphics operations like scan conversion of


Apply mathe matical logical aspects

points, lines, circle, and apply it for problem solving.

transforms to produce, position and manipulate Objects in 2dimensional and 3-


CO2: Employ techniques of geometrical

dimensional space respectively.

co3: fromaworld coordinates to device coordinates, cliping. and projections in order to produce 3D
Describe mapping

images on 2D output device.


curves and fractals using
4: Apply concepts of rendering, shading, animation, computer graphics tools in design,

of 2D,3D modeling applications.


development and testing

CO5: Perceive the concepts of virtual reality.

cOURSE CONTENTS

Unit Computer Graphice Basie,OpenGLand Line, Circle Drawing 06hrs


computer basics of graphics and random basic
Introduetion cG: Introduction to graphics, systems, raster scan,

display processor
- Graphics function, OpenGL Interface, primitives and attributes, Control functions,
OpenGL-Introduction
events.
programming
Bresenham
Drawing:DDA
Line drawing Line drawing algorithm

:
algorithm,
Line
Bresenham circle
Circle Drawing drawing algorithm.

Character Generation: Stroke principle, starburst principle, bitmap method. Introduction to aliasing and anti-aliasing,

(ReferChapters 1 and 2)

Case Study Computer-generated imagery (CG)


Mapping of Course Outcomesfor Unit I
COL
Unit I:Polygons,20 Transformatlons 06 hrs

Polygons: Polygons and its types, inside test, Polygon filling methods: Seed Fill -Flood fill and Boundary Fill, Scan

line Fill algorithms,

2D Transformations Translation, Scaling, Rotation, Reflection and Shearing, Matrix representation and

homogeneous coordinatesystem, composite transformations. (Refer Chapters 3and 4)


Case Study Transformation of an Object in Computer Graphics: Mathematical Matrix Theory
Mapping of Course
CO2
Outcomes forUnitII

Unit IH:Windowing,
Windowing :Concept
CIlpping,3D

of window and
Transformation,

vie
Projectlone

wport, viewing transformations


06 hrs

Line Clipping: Cohen Sutherland method clipping


of line
:Sutherland Hodgemanmethod

:
Polygon Clipping for convex and concave polygon clipping.

3D Transformation Translation, scaling, rotation


about X,Y, Z & arbitrary axis, and reflection about XY, YZ, XZ &
arbitrary plane.

Projections: Types of projections- Parallel, Perspective

Parallel: oblique - Cavalier, Cabinet,Orthographic


- isometric, diametric, trimetric

Perspective: vanishing points as 1


point, 2point and 3 point. (Refer Chapters 5 and 6)

Case Study 3D Rendering and Modeling

Mapping of Course Outcomesfor Unit III CO2 & CO3

Unit IV:Segments, Illumination.models, colour.models and shading 06 hr


Segments: Introduction, Segment table, segment creation, closing, deleting, renaming, and visibility.

Ilumination models: Light sources, ambient light, diffuse light, specular reflection, the Phong model, combined

diffuse and specular reflections with multiple light sources.

Color Models: CIE Chromaticity Diagram, Color Gamut, RGB, CMY, YCbCrHSVeolormodels.
Shading Algorithms: Constant intensity shading, Halftone, Gourand and Phong Shading.(Refer Chapters 7and 8)

Case Study Best practices in Day lighting& Passive Systems for


Smaller Commercial Buildings

Mapping of Course Outcomes forUnitIV CO4

Unit V:Curves,fractals and Animation


Curves: Introduction, interpolation and approximation, Spline Interpolation Methods - hermite interpolation, Bezier

curves, B-Splines.

Fractals: Introduction, Classification, fractal Dimension, Fractal dimension and surfaces, Hilbert curve, Koch Curve.
Animation: Basics of animation,
types of
animation, principles of animation,design of animation
sequc
animation languages, key frame,
morphing, motion specification.
Methods of controling animation,
frame-by-frame animation techniques, real-time animation techniques.

(Refer Chapters 9and 10)


Case Study
Mapping of CourseOutcomes for Unit V

Unit Vi:Virtual Reality *.'.


Introduction of Virtual Reality: Fundamental

systems, Applications of VR systems.


Concept, Three
3D Animation
CO4

I's
06
services

of virtual
for character expressions.

reality and Classic Components of VR


hrs

Multiple Modals of Input and OutputInterface in Virtual Reality: -3D


Input Trackers and
position its types,

Navigation and Manipulation Interfaces, Gesture Interfaces,


-
Graphics Displays HIMD and CAVE, Sound Displays
Haptic Feedback

Rendering Pipeline: Graphics rendering Pipeline, Haptics Rendering Pipeline Modeling in Virtual Reality: Concepts
of Geometric Modeling, Kinematic
Modeling, Physicalmodeling and Behavior modeling.

(Refer Chapters 11 and 12)

Case Study Virtual reality in aviation and Space travel Training

Mapping of Course Outcomesfor Unit VI CO5

O00
Index
UNIT
...1-1
Chapter 1
Basic Primitives... to1-22
...2-1
Chapter 2 Scan Conversion. to2-38

UNIT
..3-1 to
Chapter 3 Polygons... 3-20

2D Transformations. 4-1 to 4-33


Chapter 4

UNIT N
Chapter 5: Windowing and Clipping.. ..5-1 to 5-33

Chapter 6:3D Transformations and Projections.. ..6-1 to 6-29

UNIT IV
Chapter 7 Segments. ..7-1 to 7-11

Chapter 8 Light,Colors and Shading. ...8-1 to 8-15

UNIT V
Chapter 9 Curves and Fractals... ....9-1 to 9-18

Chapter 10: Animation... ..10-1 to 10-13

UNIT
Chapter

Chapter
VI

12:
11: Introduction to

Virtual
Virtual

Reality Modeling...
.
Reality ..11-1

..12-1
to 11-17

to 12-9
UNIT 1 Basic Primitives
CHAPTER 1

Svllabus

and random scan, basic


Introduction CG: Introduction to computer graphics, basics of graphics systems, raster

display processor
and attributes, Control functions,
OpenGL- Introduction Graphics function, OpenGL Interface, primitives

programming events.

**a******************** 1-3
*************************** **************

*
Syllabus Topic:Concepts.****************************
1-3
1.1 Introduction to Computer Graphics..

syllabus Topie: Applications


of Computer **********a*miten********************
** ***************************** 1-4
Graphic. .. 1-4
1.1.1 of Computer Graphics.
Applications

*** 1-4
Topic:Pixel, Frame Buffer.********
****°******** ss**
************°***°***°*****°. ******** ****************
Syllabus

1.2 Pixel and Frame Buffer .. 1-4

1.2.1 Rotating Memory Frame Buffer..

**a*******|
1-5
1.3 Basics of Graphics System. ns*t***se****d*s*******s*s*************************e*nnestes*ato*****a**

1-5
1.3.1 Video Adapters...
S...........isssnsnssenassnssensspsesamnanssss*esnasnssnne**************************************************************

*************anan*********asesso -6
1.3.2 Modes..**** ***********a****e****'*********************'***********************************.*
aannssenutosann 1-7
Graphics Mode Function..
******e*************a*a aaaos******
*stle**********n*******snt0en******
1.3.2(A)

Ratio.. 1-8
syllabus Tople:Aspect
**°°*****°**°''**° **"'°"************'******"a*******"*******°*4***** 1-8
1.3.3 Aspect Ratio.*********°* °*****°°''''****°*°***°*"

1.4
Display Devices..
Video Display Devices. **estnsnessassnsana*********************sose*********nsssassrmn
. 1-9

1.4.1

1.4.2 Raster Graphics Display / Raster Scan Display.


****"*****************************"*"""*******"****"*********s** 1-10
1.4.3 1-10
Plotters.
1.4.4 Direct View Storage Tubes (DVST) .. 1-11

1.4.5 Plasma Panel.. *********************************************s*************ss*****************me 1-11


(Basic Primitives)..Pageno (1-2
4-1T)
SPPU-Sem
Computer Graphics ,.. . . * *****************'****"*******'*************************°*****°**********esdsdseeen. 1-11
46 Vector Relresh Display

***** **************

*
}-11
******************'"***'"'****°''***********'******.*i*'*'1
1S Primitve Operahons

Structure. ****************° ******"'** *************


****"Fe
1-13

*
File
Sylebus Toplc Display

1-13
Fite ana its Structure
16
1(6b), May 18. 6Marks).
Drsolay

what is the concept of display file and display file interpreter. (SPPU-0. 1-1a

Ua.
1-13
Prmitve Operations on Display
File. * ************************************e*************************
Sylabus Topic
6 Prmitve Operations on Display File.. 1-13

1-14
*

I
File ****** *n*os00***************************************,
Toplc: Dispiay Interpreter..
*******s***
Sylilebus
************* .1-14
6.2 DrSDlay Fie Interpreter. ****'**'*************"*************************************1

***************** 1-15
Raster and Random Scan..... **********''*************************°*"*********************'**********e******

Ua. Difterentiate between Raster scan and Random scan


e*a*s***************** 1-15
SPPU-. 1(a). Dec. 18, 0.1(b), May 19, 6Marks).. *****e******* ******************

1-15
.71 Aovantages of Random Scan..
**************** -15
1.72 Drsadvantages of Random Scan. *sosnteess sstsese*********tseteop*as**lls*t********

I 5
1.7.3 Differentiation of Random and Raster Scan.
***********e*****************************s **sa****a*************s

1.8 aaa**o*oeseco******s***0*******a*ss**** 1-16


Co-ordimate Systems.
.1-16
1.8 1 Co-ordinates
in Two Dimensions.*********""*s************s********esenbpos****************"******** *******************aesdssos*

1.8.2 Co-ordinates in Three Dimensions.. .*******nsornnenesssesnsapac 1-16

Sylabus Topic: Interactive Graphics Tool


-
OpenGL.. ****srseesnnsnea**sas**sunaesenne*********************************** 1-17
1.9 introducbon to
7
OpenGL.
Write ashort note on OpenGL (SPPU-O.5(b),. May 18,0.5b),Dec.18,6Marks). ******************sssmnanan
°U
-17

Ua. Explain OpenGL with respect to OpenGL operations. (SPPU-0.6b(OR),May 19, 6 Marks). 1-17
1.9.1
OpenGL Architecture. **esssansssnssonssanassngsssssspnsen**nssopes*s*sensse************************* *********e**********sss**a*ten****1-17
1.9.2 Functions and Features of 1-18
OpenGL.
.************ssssssssssrsttesrn**nasssasne*stnssnnan sannnsanssenuaanennn

1.9.3 OpenGLPrimitives and


Atributes..
***************so*******s'*******'********'******s'as*asss***********a**********sst********s"e*******e*as**
7-19
1.9.4 OpenGLLibrary.. -19

1.9.5 Programming Essentials. *******0* 1-19


1.9.6 Event Driven Programming. 1-20
**************taesents******se*** rssssnesnsn*unsssnneseo*sassnssssnsanses

1.9.7 Keyboard and Mouse interaction in


OpenGiL. 1-20

Chapter Ends..
******esaas********senss****s*****************.*ssssssssssss*sssssasssssnsspnonssssssssessssststriss 1-22

PU-New Syillabus wef academic year 20-21) (P4-28) Tech-Neo Publications...A SACHINSHAH Venture
Computer Graphics(SPPU-Sem.4-1T)

1.1
SyllabusTopic: Concepts

INTRODUCTION TO
GRAPHICs
cOMPUTER
A

may be
machine can
thousand entries

worthless

time to go through
easily

for
(Basic

a
if the

it
generate

table.
Primitives)...Page

human
or understand
hundred
But such a code or
reader

it. If
lines

does not
the
of
no (1-3)

code or
table

reader is
InS
haven
I
Unit

Sem.
not going to read all the hundred lines of codes and

analyze it then he will be doubtful about the output of


Anything which is not a text on computer is treated as a
that code. So even if the code may be correct as reader
computer graphics. Nowadays almost all computers are
is not reading it sincerely, he is doubtful about the
using graphical user interfaces. This is because users
code. At this stage Computer Graphics is very useful.
are not interested in doing any operation by giving
Graphics is the of to
textual command. Rather the
operations are done bv 7LComputer study techniques

icons and GUT's. improve communication between human and machine.


using different
The word Computer Graphics means graph or
The term Computer Graphics has several pitures,
meanings like

the representation and manipulation of pictorial


scene is drawn with the help of computer. We can draw
data by a graph which may replace that huge table of thousand
a computer, the various
technologies used to create and entries and allow the relevant
reader to note the
manipulate such pictorial data, the images so produced,
patterns and characteristics at a glance. Here Computer
and the sub-field of computer science which studies
represents the data provided to it in pictorial form. The
methods for digitally synthesizing and manipulating
input given by the user, often alter the output presented
visual content, see study of computer
graphics.
by the machine.
Today computers and computer generated pictures are A dialog can be established through the graphics
becoming integral part of our daily life. Computers are medium. This is termed as Interactive Computer
used in many versatile fields like television, Animation
Graphics. Here user interacts with machine.
films, medical science, simulation fields, etc. A range e.g. Histogram
of tools and facilities are available to enable users to
Here we will provide input data to machine as result of
visualize their data, and computer graphics are used in
F.E. to B.E.
many disciplines.
For F.E. result is 70% For S.E. result is 80%
The computer is a data processing machine or we can
it is a tool which is used for storing,
For T.E. result is 65% For B.E. result is 90%
say manipulating

and displaying data. We can collect or generate data

and process itaccording to users need. Let us say data 0


is entered from keyboard in the form nos., say 10
of2
and 20. Now we can process this data by performing 80
some operation on it, say addition, so that we will get
70
result as 10+20 =30. Here 30 is a result.
It means here
65
we have performed addition process on input data. This
data is also called as information. This information can
F.E S.E T.E B.E
help us to make decisions and understandthe world and
Year
control the operations. If the data elements are less in
Fig. 1.1.1
numbers then we can easily perform any operation.

But as the volume of information increasesa problem


If we draw histogram with this database it be easy
will

to understand and analyze the result of F.E. to B.E.


arises. Problems could be of type, more time required

to accuracy problem, understanding may


i.e. which class is having maximum result, which class
process data,
be difficult etc. So, how can this information be
is having minimum results etc. See Fig. 1.1.1. So,just
large

and efficiently transferred between machine by working at one diagram we can answer many
effectively

and human? questions.

(SPPU-New Syllabus w.e.f academic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
Computer Graphics (SPPU-Sem.4-1T) (Basic
Primitives)..Pageno(1-4
we can the The the smallest
B hangng the input puameters modify pixel is addressable screen eleme
if F.E. result increases from 70% to is the smallest t.It
upur peture ie. piece of screen
the display which we
sO then crnainly the histogram is going to change. control.

the other could be Pie-charts, Each has name or The names


Similarly ex amples pixel address.
whi
Cardogram ete. Cardiogram takes heart pulses as input to the coordinates
h
identify pixels correspond which
and converts that input on graph paper.
identify points.

Compurer graphics allows communication through are made by


Computer graphics images setting the
pictures. charts and diagrams, as there is old and of which
adage intensity color the pixels compose the
Thousand words can be replaced by a single screen.
picture".

We draw line segments by setting the intensities


that is
Syllabus Topic Applications of Computer the brightness of a string of pixels between a
Graphics starting

pixel and an ending pixel. We can think of the

a 1.1.1 Applicacions of Computer Graphics


screen

integer
as a grid,

coordinate
or array,

values to
of
each
pixels.

pixel.
We
Starting
shall
display

give

at the

There are many applications of computer and left with 1, we shall number each column.
graphics

variery of field's in which it is


applied such as, Starting at the bottom with 1, we shall number each

Software, Business Software. row. The coordinate (i, j) will then give the column and
Engineering/Scientific

T.V. channels.
row of a pixel. Each will be centered at
space simulation training. pixel its

coordinates. See Fig. 1.2.1.


PCB designing. map preparation.
We may wish to place the intensity values for all pixels
User Interface, Animation.
into an array in our computer's memory. Our graphics
Making Charts, Image Processing.
display device can then access this array to determine
Office Automation. the intensity at which each pixel should be displayed.

Desktop This array, which contains an internal of


Publishing. representation

the image, is called the frame buffer. and


CAD/CAM. It collects

Art and Commerce.

Process Controlling.
stores pixel values for use by the
5 7T8 9 display device.

10

Visual Effects' in Movies and Computer Games.

SyllabusTopic: Pixel, Frame Buffer

1.2 PIXEL ANDFRAME BUFFERR


We cannot represent an infinite number of points on a

computer, just as we cannot represent an infinite

quantity of numbers. The machine is finite and we are

limited to a finite number of points making up each Fig. 1.2.1

line. The maximum number of distinguishable points


The information in the memory buffer typically
which a line may have is a measure of the resolution of
consists of color values for every pixel on the screen.
the display device.
Color values are
commonly stored in 1-bit binary
The greater the number of points, he higher is the
(monochrome), 4-bit, 8-bit, 16-bit high color and 24-bit
resolution. Since we must build our lines from a finite
true color formats. When the color value is 1 bit it is

number of points, each point must have some size and


as black For more
referred and white frame buffer.
so is not really a point at all. It is a pixel.
number of color values it is referred as color frame

(SPPU-NewSyllabus we.facademic year 20-21) (P4-28) STech-Neo Publications.A SACHIN SHAH Venture
Computer Graphics (SPPU-Sem.4-1T)
(Basic Primtives)..Page no (1-5)
buffer. An additional alpha channel is Unit
sometimes used
to retain information

The total amount of


about pixel

the
transparency.

memory required to drive the


1111011
11101 InSem.
frame buffer depends on the resolution of the output
10 1 11
signal, and on the color depth and
palette size.
1010 11
Frame

displays
buffers

that were
differ

common
significantly

prior to
from the

the advent of the


vector 01111
frame buffer. With a vector
display, only the vertices of
Fig. 1.2.2
the graphics primitives are stored.

The electron beam of the output display A common implementation of frame buffer is a
is then
commanded to move from vertex to vertex, random access semiconductor memory. Frame buffers
tracing an
can also be implemented Shift Each
analog line across the area between these points. With a using Registers.

frame the electron beam Shift Register contributes one in a horizontal scan
buffer, is commanded to trace pixel

a line.
left-to-right, top-to-bottom path across the entire

screen, the way a television renders a broadcast signal. 1.2.2 shows a shift of
Fig. Register implementation

At the same time, the color information for each point


frame buffer. Shift Register Frame Buffer memory
on the has the disadvantage of low levels of interactivity. In
fromthe frame
screen is pulled buffer, creating a

of discrete workstations, it is efficient to add a graphics processor


set picture elements (pixels).
with a frame buffer memory. The system
separate

1.2.1 Rotating Memory Frame Buffer performance can be improved by this architecture as it
meets the update requirements of the frame buffer.
This is the situation when we use Screen resolution less

than the maximum screen resolution supported by the 1.3 BASICS OF GRAPHICS SYSTEM
Visual Display Unit.

In case of maximum screen resolution the frame buffer 1.3.1 Video Adapters
memory is fully utilized and only one page is available
A video adapter or display adapter is an integrated
for
display. For such a resolution, when it is less than
circuit card in a computer that provides digital to
the maximum resolution, more than one page is
analog converter, video RAM anda video controller so
available. This we often use for animation using page
that data can be sent to a computers display.
flipping Characteristics of
We keep drawing on to one page which is hidden and Display Adapters
flash it altogether when the
drawing is complete with
the existing one on the screen. This avoids showing of A. Resolution

the partially drawn images. For any particular case


B. Color depth
even 3-4 pages may be available. So the system is

termed as "Rotating frame buffer" in Computer C. Refresh rate

Graphics. We keep rotating the pages to generate

animation.
D. Acceleration

A different situation where the frame buffer is literally


Fig. C1.1: Characteristics
of display adapters
rotated to a rotated display
of any image is
generate

also sometimes refered to as Rotating frame buffer. A. Resolution


Just changing the signs and interchanging the X-Y
Resolution refers to the number of dots on the screen.
coordinates may generate such an effect. See Fig. 1.2.2.
It is expressed as a pair of numbers that the
give
number of dots on a horizontal line and the number of
such vertical lines.

(SPPU-New Syllabus
we.f academic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
(BasicPrimitives)...Page no (1-6)
(SPPU-Sem.4-1T)
Computer Graphics
The CPU has to send a command only to
perform ma
Four resolutions are in common use today.
task and rest will be done by this Accelerator chin
640 x 480 2. 800 x 600 hip.
1.
Suppose we need to draw a line then we will send
only
024 x 768 4. 1280 x 1024
the end points and the color of the line, the pixels on
3.
on
colors by combining to end point are
Computer display generates that line from starting point drawn by
and Blue. These are
amounts of Red. Green
colors
the Accelerator chip by a specified color. There is no
3 wires in the display cable. Each has a
controlled by need to calculate the intermediate points in the line by

variable amount of voltage represented by a number the CPU.


from 0 to 255. This produces upto 16 million possible
the speed of
In that way it accelerates
drawing the
colors.
objects.
The accelerator chip also reduces the data

B. Color Depth transfer rate amongthe CPU and display device.

Color Depth (numberof colors) is determined by the Example 1.3.1: Find the refresh rate
of a 512 x 512 frame

hold color buffer, if the access time for each pixel is 200 nanoseconds
number of bits assigned to value.

(ns).
1. 1 bit-2 colors (blackand white)
- 16 colors Solution:Ifthe frame buffer is of 512x 512 size, then
2. 4 bits
means the total number of will be 512 * 512

3
it pixels

8bits -256colors i.e. 2,62,144.

4. 16bits 32 thousand colors For each pixel the access time is 200 nanoseconds.So
5.
24 bits-16 million (high color) 2,62,144200 =5,24,28,800 nanoseconds (ns).
6. 32bits - latest (true color)
1.3.2 Modes
The display adapter stores a value (4 to 32 bits) in

memory for every dot on the screen. The amount of


GQ What are the different video display adapter modes.
***** ****** -*-***-*-
needed is determined the
storage by multiplying
There are many video adapters which supports several
number of dots (resolution) by the memory required for
different modes of resolution. Generally all these
each dot. e.g. for VGA having resolution 640 x 480
modes are grouped in two broad categories.
with 4 bit color 256 KB memory is required. SVGA
having resolution 800x 600 with 8 bits color, will need Video Adapter Modes
512 KB memory.

C. Refresh rate
A. Text mode/character mode

Refresh rate is but the speed by which a Graphics mode


nothing

particular dot on the screen is getting printed.


Fig. C1.2: Video adapter modes
Initially VGA display monitors were using 60 Hz
frequency, but it was producing flickering effect, so A. Text Mode
later on it uses 70 Hz, to lower down this flickering
rows
effect. When a display screen is divided into number of

is
and columns of boxes then the mode of display
We can set this refresh rate by making use of drivers of
a
referred as a text mode. In text mode each referred box
particular display adapter.
is capable to hold a single character only.

D. Accelerator are used


Almost all the standard video adapters which

for this mode. In this mode


Accelerator is an computer graphics, supports
chip integrated chip existing on the
display adapter. It isused to draw the screen is divided into 25 rows and 80 columns.
readymade shapes
like drawing lines and boxes, In this scenario the screen of the is considereu
filling the color in the display

box, background and a single


filling color
managing the mouse as an array of blocks, where each block stores

pointer. ASCII character. See Fig. 1.3.1.

w.e.f academic year (P4-28) SACHIN SHAH Ventue


(SPPU-New 20-21)
Syllabus alTech-Neo
Publications..
Computer Graphics(SPPU-Sem.4-1T)
(Basic Primitives)...Page no(1-7)
Unit
In text mode it is possible to display or capture only

text in terms of ASCII. But in graphics any type of


26 rowe figure can be displayed, captured
and animated. In Sem.
"graphics.h" and "graphics.lib" are the two files which
we need to carry out any graphics related operation.

These are the standard header and library files. To


80 columns
execute the graphics program we need a display device,
Fig. 1.3.1 such as CGA, EGA, VGA, which is
etc., compatible

B. Graphics Mode
with

how
graphics

to write a
mode
simple graphics
functions. Let us have a look

program.
at

In addition to text mode, most video adapters support a Sample example to draw line *
graphics mode. in which the display screen is divided #includesldio.h>
into an array of pixels.
#includegraphics.h>
Here we are introducing new temm pixel. void main)
Pixel is the smallest addressable screen element. It is {
piece of the display we can
the smallest screen which int gd=DETECT,gm;
control. Each pixel has a name or address, so we
that
initgraph(&gd, &gm, "c:/te/bgi ");
can uniquely identify that.
Computer Graphics images line(200,200,100,100);
are made by setting the intensity and color of the
closegraph0;
pixels.
restorecrtmode0;
The output in graphics mode looks more and
perfect
smooth. We can display of shapes
unlimited variety
and
GRAPHICs.H,header file contains definitions of all
fonts by making use of graphics mode. But in case
the functions and constants. While
graphic
of text mode we are getting many limitations.
GRAPHICS.LIB file contains standard graphic
We can't increase the font size or change the shape of functions. Here we are dealing with graphic mode
the character. Also we can't achieve the free hand function. By default system sets Text Mode. To switch
shapes. Al this issues can be achieved by graphics from mode we have
text to graphic mode, function
mode. called as "initgraph".

Graphics Mode
functions

480 1. Initgraph
wwww.wwwwwwwwuw

2.Path ("C:/tc/bgi')
w.w.www
3.Line()
640
4.Closegraph()
Fig. 1.3.2
Restorcrtmode()

1.3.2(A) Graphics Mode Function


Fig. C1.3:Graphics mode functions
GQ. Explain different
graphics mode functions. 1. Initgraph: Initgraph() is
areadymade function

GQ. Explain
-******
the use of initgraph0 command. which is used to initialize the graphic mode for our
system. It selects the best resolution for our PC and
We will cover some of the standard library functions

here. As we assigns that value to mode in variable gm. The


have seen that, there are two different
variables 'gd' and 'gm' are the two integer variables
modes, namely text mode and graphics mode.
which are used for storing the driver and graphics

(SPPU-New Syllabus w.e.f academic year 20-21) (P4-28) LTech-Neo Publications.A SACHIN SHAH Venture
(Basic Primitives.Page no(1-8)
Computer Graphics (SPPU-Sem.4-IT)

graphics mode for your system. When we resolution. If we have a monitor having
resolution
are writing. of

gd DETECT, it means the 640 x 480, then aspect ratio will be width /
highest possible value height of a

available for the detected driver is assigned to 'gd'. We pixel, i.e. 640/ 480= 1.33. Because
of aspect ratio of
can assign some fixed value also for the even if we are trying to draw a circle on
variable 'gd' pixel, screen
and 'gm. Since we are passing the address of the we will not get exact circle, but we will
get ellipse.
constants we are using '& symbol for initgraph(). since pixel is having width more than height. Refer

2. Path ( "C:/tc/bgi") : It
specifies the directory
Fig. 1.3.3.

8Inches
path where initgraph looks for graphies drivers
(*.BGI)
first. If files are not there then
initgraph will look for
the current of your
directory program. If it unable to
find it then it will
generate an error. We can 6 Inches Aspect Ratio =8/6
leave it 1.33
blank")ifthe *.BGI files arewithin the working
directory.

3. Linel ): inbuilt
line function takes X1,Y1 and Fig. 1.3.3
x2.Y2 values with respect to
top left corner of the

and
For instance, the aspect ratio of TV sCreen is
screen third co-ordinate. In this
example we have
4:3,

passed X1 = 200, Y1 =200 and X2 =100 and Y2 = or 1.33:1. The aspect ratio of a standard 35mm film

frame is around 1.35:1.Within the motion


100 interms of pixels as picture
arguments. The line function
industry, a cinemascope frame is described as 2.35:1 or
will draw a line for the said coordinates on the screen.
just "2.35
4. Closegraph() The closegraph) command is The aspect ratio for 70 mm file frame is 2.20:1. But
used to come out of graphics mode and sets the
display when time comes to transfer the 70mm or cinemascope
mode to its text mode. If we don't use
original this films to home TV, there was a problem with the wider
function then we may not be able to see the cursor
aspect ratio. They are too wide to fit in the TV screen.
blinking. Because cursor is a text mode character and So there are two to deal with
ways this problem namely
not the graphics mode character. And characters could
pan and scan method and letterbox transfer method.
be displayed as smalland bold on output window.
The pan and scan process has the video camera
5.
Restorertmode( ): This function is used to scanning back and forth during the transfer to keep the
restore the original video mode. most important action centered on our TV screen. It

means the film has been modified in some


way to fit

Syllabus Topic:Aspect Ratio our TV screen completely.

The problem with this is we are loosing 50% of the

1.3.3 Aspect Ratio original film. To avoid this loss we preferring letterbox

format, in which the entire film image is presented and


Aspect ratio is the ratio of width to height. It is used in
black strips are filled in the unused screen area. See
number of fields, but is most commonly used when letterbox technique from Fig. 1.3.4.
talking about images.

In
imaging terms, aspect ratio is the width of image
Black Strips
divided by its
height (usually expressed as "x: y"). If a
picture has aspect ratio of 2:1, it means that the width is Actual Picture
twice as large as the When
height. resizing picture, it is

important to maintain the aspect ratio to avoid


stretching the picture out of proportion.

In it is
computer graphics used to describe the shape of
an individual pixel. Most systems use Fig. 1.3.4
square pixels
i.e. having same resolution and
horizontally vertically.
But there are some devices that do not have the samne

w.e.facademic year 20-21) (P4-28)


(SPPU-New Syllabus Tech-Neo Publications..A
SACHIN SHAH Venture
.
Computer Graphics (SPPU-Sem.4-1IT) no (1-9)
(Basic Primitives)...Page

1.4 DISPLAY DEVICES


8Ebctron
guns
Uniu

Display Devices In Sem.


nasusisiiiimomgro-

a)Video Display Devices


Phospher
dols in

Red Shadow
(b) Raster GraphicsDisplay / Raster
triad
patem
o
Scan Display Blue dreen

c) Plotters

Fig. 1.4.1
(d)Direct View StorageTubes (DVST)
Phosphor is coated on the inside of the display screen

which emits a of time when


(e)Plasma Panel lights for period hit by a

beam of The color of light and time period

0
electrons.

Vector Refresh varies from one type of phosphor to another. The light
Display
given off by the phosphor during exposure to the

electron beam is known as fluorescence, the continuing


Fig. C1.4: Display Devices
glow given off after the beam is removed is known as

The basic question in


computer graphics is how to phosphorescence and the duration of phosphorescence

locate and and


is knownas the phosphors persistence.
display points line segments. There are

several hardware devices which may be used to display Opposite to phosphor-coated screen i.e. on other end
there is an electron gun which is heated to send out
images.
electrons.

1.4.1 Video Display Devices The and


electrons are regulated by the control electrode

forced by the focusing electrode into a narrow beam


GQ.Explain the working principle of Video Display
striking the phosphor coating at small spots. When this
devices in brief.
electron beam passes through the horizontal and
There are two types of video monitors. vertical deflection plates, it is bent or deflected by the
electric field between the plates.
Types of video
monitors The horizontal controls the beam to scan from left
plate

to right and retrace from right to left. The vertical


A. Monochrome display monitor
plates control the beam to go from the first scan line at

the top to the last scan line at the bottom and retrace
monitor
B.Color display
from the bottom back to the top. These actions are

Devices synchronizedby the control circuits so that the electron


Fig. C1.5:VideoDisplay
beam strikes each and every pixel position in a scan
Let us first see the Monochrome monitor
display line by scan line fashion.

(Black and white).


The intensity of the light emited by the phosphor

A. MonochromeDisplay Monitor coating is a function of the intensity of the electron

beam. The control circuits shut off the electron beam


It
mainly consist a Cathode Ray Tube (CRT) along horizontal and vertical retraces. The of
during intensity
with related circuits. The CRT is a vacuum glass tube
the beam at a particular pixel position is determined by
with the display screen at one end and connectorsto the the intensity value of the corresponding pixel in the
control circuits at other end. See 14.1.
Fig.
image being displayed.

(SPPU-New Syllabus w.e.f academic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
(Basic
Primitives)..Page no(1-10)
(SPPU-Sem.4-1T)
Computer Graphics

Color Display Monitor


B.
are 3 electron guns instead of one
there
In color display
each primary color. See
with one electron gun for

Fig.
1.4.2. User Frame
Raster
Electron gun buffer
program display
Conneclors

Fig. 14.3
***
In raster display, which is shown in
Fig. 1.4.3, the
Control electode

Soan n ****. frame buffer may be examined to determine what


Focusing electrode is

currently being displayed. Surfaces or lines


Honzontal dellecion plates may be
displayed
on raster display devices.
HOMZonta
Verlical dellecton plates

The raster terminal can also display color images.


One
Electron beam
of the problems with the raster display is the time

coaled
which may be required
to alter every pixel whenever
Phospher
reen the image is
"Vertical changed.
retrace
Another disadvantage is the cost of the required
Fig. 1.4.2
memory. So, in the past, the cost of memory made the

The phosphor coating on the inside of the display


raster display less promising.
screen consists of dot patterns of three different types So one approach was to let the medium
display

of phosphors.These phosphors are capable of emitting remember the instead of computer Memory.
image,
Red, Green and Blue light. The distance between the This is what do.
plotters
centers of the dot patterns is called the pitch of the
color CRT. 1.4.3 Plotters

A thin metal screen called a shadow mask is placed


the working principle as display
GQ.Explain of plotters
berween the coating and electron guns. The tiny holes
device.
on the shadow mask constrain each electron beam to hit

its corresponding phosphor dots. When viewed from a


certain distance, light emitted by the 3 types of

phosphors blends together to give us a broad range of


colors.

User program Plotter


1.4.2 Raster Graphics Display / Raster Scan
Fig. 1.4.4
Display
A pen is lowered onto the paper and moved under the
f we want to get a good resolution say 1000 lines on direction of a vector generation algorithm.
both x and y directions, then the screen would have
(See Fig. 1.4.4)
resolution 1000 x 1000 i.e. I million pixels. And each
Once the line is drawn, the ink on the paper remembers
pixel needs at least one bit of intensity infomation,
it and computer need not consider it further.
light or dark and further bits are needed if shades of

different colors are desired. Thus, if we want to


But once a line is drawn, it cannot be removed.
store easily
the information for each pixel in
computers memory a Ifwe change the image on plotter a line,
by removing
lotof memory may be This we have to get new paper and redraw the whole
required. is in fact what is
picture.
done in raster graphics
display. For this reason are not best devices for
plotters
A of system interactive
portion memory which is used to hold the graphics.

pixels is called as
framë buffer.

(SPPU-New Syllabus w.e.facademic year 20-21) (P4-28)


Tech-Neo Publications.A SACHINSHAH Venture
Computer Graphics (SPPU-Sem.4-IT) (Basic Primitives)... Page no (1-11)
Unit
a 1.4.4 Direct View Storage Tubes (DVST) a1.4.6 VectorRefresh Display
I
the working principle of DVST GQ.Explain the working principle of Vector Refresh In Sem.
GQ. Explain as display
Display.
device
Another to the of graphical
CRT is a low cost and most widely used device. The approach display

information is the vector display.


terminals or devices use special CRT called Direct refresh

Tubes but it
View Storage (DVST) which behave much It also stores the image in computer's memory
similar to plotter. tries to be more efficient than raster display.

An electron beam is directed at the surface of the To specify the line segment we need co-ordinates of

screen. The position of the beam is controlled


end points. But the raster frame buffer stores not only
by
electric or magnetic fields within the tube. Once the
the end points but also all pixels in between. The vector

the commands for


screen phosphors of this special tube by the electron refresh display stores only necessary

beam. they stay lit. drawing the line segment.

Similar to one cannot alter the DvST In vector refresh display input is saved, instead of
plotter image
the entire These commands are saved in Display files.
except by erasing screen and drawing it output.

again. This can be faster than plotter but still not


efficient and is a time consuming process.
Line (4,5)

a1.4.5 Plasma Panel User program Display


file
Display
GQ. Explain the working principle of Plasma Panel as
Fig. 1.4.6
display device.

The commands in display files are examined and lines


A display device which stores the image but allows
are drawn by appropriate algorithm (See Fig. 1.4.6).
selective erasing is the plasma panel.
Vector refresh display allows alteration of the image.
It contains a neon gas at a low pressure sandwiched
The disadvantage is images are composed of line
berween borizontal and vertical grids of fine wires.
A between a segments not surfaces or pictures and a complex
(See Fig. 1.4.5) large voltage difference

because will take long time to


horizontal and vertical wire will cause the gas to glow display may flicker it

as it does in a neon street sign. analyze and draw it.

A lower will not start a glow but will maintain The concept of display file is very useful. It provides an
voltage
wires have this low interface between the process and
a glow once started. Normally the image specification

between them. image display process. It also defines compact


voltage
of image, which may be used for later
To set a pixel, the voltage is increased momentarily on description

the wires that intersect the desired point. To make pixel display.

off, the voltage


on the corresponding wires is reduced When the display file idea is applied for the devices

until the glow cannot be maintained. other than refresh display then that file is called as

Plasma are very durable and are often used for pseudo display file or metafiles.
panels

military applications.
M 1.5 PRIMITIVE OPERATIONS

GQ. What are the basic primitive operations supported by

display device?
-* -** ***-********

Regardless of the differences in display devices, most


graphics systems offer a similar set of graphics
primitive commands.
Fig. 1.4.5

(SPPU-New Syllabus w.e.f academic year 20-21) (P4-28) Tech-Neo Publications...A SACHIN SHAH Venture
(BasicPrimitives)..Page no(1-12)

Computer Graphics (SPPU-Sem.4-1T) is another type also, which is called as Rel.


line
There lative
commands to draw
Now we will see the primitive
line command.
draw any line segment we need
2 points,
segment. To line command we indicate how for to
move
1.5.1. In relative
a line AB. See Fig.
let's say we have drawn from the current position to
direction
in x and y reach

See Fig. 1.5.4.


B the final point.
be
The command used
will
A
line-Rel (Dx. Dy)
are not actual co-ordinates, but
where Dx and Dy thevy

distance from current x and y point to


B indicate relative

final point.

X,Y

DY
Fig. 1.5.1
DX
If we want to join another line BC to this line segment Current

AB then it will become ABC because we are adding point

BC at end of AB line segment i.e. often the segments


1.5.4
Fig.
drawn are connected end to end.

be the may that we want to draw two


point of first segment will But happen
it
It means the final

which is disconnected segments as shownin Fig.


1.5.5.
starting point for next segment. In the example
AB BC
This can be accomplished by the same
shown in Fig. 1.5.2, segment is drawn first then mechanism if

then CD and so on i.e. Final point of segment AB, we draw these two segments as connected by a middle
which is B, is acting as starting point
for next segment BC which happens to be invisible as shownin
segment
BC. Fig. 1.5.6.

Usually to draw single


line segment we need two

points, similarly to draw two lines we need four points.

But we can draw two line segments by just three points

only because here one is common.


point
C

Fig. 1.5.5

So we need a command to move the current position


Fig. 1.5.2
without drawing line between BC or by drawing
In this case then command becomes :draw a line from invisible line BC. See Fig. 1.5.6. For this purpose we
ie.

:
the current to the
position specified point. say have to use command,Move-abs (x, y)
command as line-abs (x. y)
Where (x, y) indicates new position for the current
Here x andy are actual final co-ordinates. It means we
point.
are going to draw a line from current position to point

(x. y). See Fig. 1.5.3. Such commands are called as

Absolute line commands.

X,Y

Current
Fig. 1.5.6
position

Similarly we are having another command.


Fig. 15.3
Move-Rel (Dx. Dy)
Where. Dx and Dy indicates relaive pusituon

academic year 20-21) (P4-28)


**"
SPPU-New Sylabus w.e.f
Tech-Neo Publhications. A SACHIN SHAH Vent
Computer Graphics (SPPU-Sem.4-IT) (Basic Primitives)...Page no (1-13)

File Structure Now we can access a command from this Un


Syllabus Topic:Display
display
file very easily.
particular

e.g. I Sem.
1.6 DISPLAY FILE ANDITS STRUCTURE
Opcode (oP)array X-op arrayY y-0parrayY
In

UQ. What is the


concept of display file and display file

interpreter. (SPPU-Q 1(b),May 18, 6Marks)


***
10 10

We are aware that in the raster graphics displays

pictures are stored in frame buffer which holds

information about all pixels whereas in vector refresh

displays we use commands to store the picture which


we want to display. So in vector refresh displays we are Suppose we want to access second command then we
commands i.e. of output. will just
storing input instead say

The file in which we are storing these commands to op [2]. x-op [2], y-op [2].

draw picture is called Display File.

In this file we are goingg to store command by SyllabusTopic: Primitive Operations on


display
Display File
proper way. Each command in display file, we are

breaking it two parts: opcode and operand.


into
1.6.1 Primitive Operations on Display File
Opcode is nothing but a command, which will be like
Move or Line etc. and operand will be parameters
GQ Whatarethe primitive operations ondisplay
file?

e.g. move (10, 10)


Let's assume that we want to draw a rectangle ABCD.
Here we will break this command in opcode and
Then we will perform following steps:
operand as,
Step I:Move to point A which may be (x, y,). See Fig. L6.1.
Opcode Operand
So our commandwill be, Move (x, y)
Move 10, 10
We will represent this command in opcode and operand
now we have seen only two primitive
Uptill command
form by (1, X,. Y)
Move and Line. So initialize opcode 1 for Move

command and opcode 2for Line command. where 1 means Move command

Command x indicates x co-ordinate of point A


Opcode
y indicates y co-ordinate of point A
1 Move
2 Line

As operand is having both x and y parameters we have


to separate them. So we will store the x co-ordinate in x
A
operand and y co-ordinate in x,Y.
y operand.
So now our command (move(10, 10)]will become.

)
Fig. 1.6.1

Opcode (op) X-op y-op


10 10 Step II:Draw line from A to B
So command will be

(
line
This is what about one command. But in file (x
display
the of point B.
there will be many commands. So we will use arrays to where y) are co-ordinates

store
opcodes and operands. (See Fig. 1.6.2)

Again we will command in the form of


Opcode (oP) array op array -oparray opcode and operand
represent

as, (2, x2»


this

y2)

where 2stands for line command.

(SPPU-New academic year 20-21) (P4-28) SACHIN SHAH Venture


Syllabus w.e.f Tech-Neo Publications...A
(Basic Primitives)..Page no
(1-14)
Computer Graphics (SPPU-Sem.4-1T)

BX2.Y2

XY
Fig. 1.6.5
Fig. 1.6.2

Now our display file for this rectangle ABCD will look like.

Step III: Draw line from Bto C


Opcode x-op y-op
So command will be, line (xg y)

will be the co-ordinates of point C.


where (X. ys)

(See Fig. 1.6.3)


2 2
Now we will represent
this command as

(2.X Ys) 2
where 2stands for line command.
2
Now this display file is containing what to display on
screen.

Syllabus Topic: Display File Interpreter

Fig. 1.6.3 1.6.2 Display File Interpreter

Step IV:Draw line from Cto D The display file will contain the information necessary
So command will be ,line (xg Ya)
to construct the picture. Saving the instructions
usually

where (x takes much less storage than saving the


y) will be co-ordinates of point D. picture itself.

These instructions are nothing but a sample


(SeeFig. 1.6.4) programs.
And the command will be, (2, x4, ya)
Each instruction like move or line indicates some
action for display device. So we need something to
convert these instructions into actual
images. That
conversion is done by display file It
interpreter.
interprets each command from display file into some
action on display. (See Fig. 1.6.6)

Interpreter may be a part of machine which


executes
Fig. 1.6.4 these instructions. The resultof execution is
image. In
where 2stands for line command.
some graphics systems there is
separate computer
StepV:Draw line from D to A which handles this
job which is called display
Socommand will be ,line processor.
(x,y1)
where (i, Yi)
represents point A. i.e. we have to close User
Display
the rectangle. See Fig. 1.6.5. As we are drawing
have represent this
line so we program file Interpreter Dlsplay
command as, (2,
X Y1)
where 2stands for line
command.
Fig. 1.6.6

Display file
interpreter serves as an interface between
our
graphics program and the
display device.

SPPU-NewSyllabus w.e.f academic year 20-21) (P4-28)


LdTech-NeoPublications...A
SACHINSHAH Venture
Computer Graphics(SPPU-Sem.4-1T) (Basic Primtives)...Page no
(1-15))

1.7 RASTER AND RANDOM SCAN 2. Random scann


Unit
*

Display devices with random scan operate by directing Iu Sem.


GQ. Define random scan and raster scan
beam to only those parts of the screen
displays.
the electron
UQ. Differentiate between Raster scan and Random scan. called as
where the is to be drawn. This is also
picture
(SPPU Q 1(a),Dec.18,Q.1(b),May 19, 6Marks) ********
vector graphics. This vector graphics depends on the
of hardware to generate line vectors. Creation of
two ability
There are different ways of scanning video
vector becomes easier, so can
These are called as raster and random scans. diagrams using graphics
displays.
be used in engineering and scientific drawings, whereas
Ways of scanning
video displays the raster graphics can be used in animation.

In random scan and direct view


pen plotters storage
1. Raster scan
tubes (DVST) devices are used, whereas in raster scan
cathode ray tubes (CRT)
are used. Since the cost of
2. Random scan
devices used for random scan is much higher than the

Fig. C1.6: Ways of scanning


video displays cost of devices for raster scan, people are using raster

1. Raster scan
1.7.1
scan devices heavily.

Advantages of Random Scan


In raster scan the electron beam follows a fixed path as
shown in Fig. 1.7.1. The electron beam starts at top left
GQ. What are the advantages of Random Scan
corner of the screen and moves horizontally to the

right. This defines a scan line. Very high resolution, limited only by monitor.

of the beam modulated draw at different


During the scan the intensity is Easy animation, just positions.

according to the pattern of the desired image along the


Requires less memory.
line. At the right corner of the screen, the beam
becomes off and moved back to the left edge of the 1.7.2 Disadvantages of Random Scan
***. ********
point on next
screen at the starting
line. This is shown

as dotted line, which is called as horizontal retrace


GQ What are the disadvantages of Random Scan?

This way of scanning is continued til the bottom right electron beam, i.e.
Requires intelligent processor
corner is reached. At this point, one scan is completed. controlled.

The beam is then at the top left corner of before have flicker, can't draw a
repositioned Limited screen density

the screen for starting another scan. This movement of


complex image.
beam from bottom right corner to top left corner is
Limited color capability.
called as vertical retrace.
For random scan the host system generates a display

file of graphics commands which is executed by the


display processor.
The display processor then just reads
the frame buffer and turns the electron beams on/off.

1.7.3 Differentlaclon of Random and


Raster Scan

GQ. Differentiate between Random Scan and Raster

Scan?
Fig. 1.7.1

(SPPU-New Syllabus w.e.f academic year 20-21)(P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
Computer Graphics (SPPU-Sem.4-1T) (Basic
Primitives..Page no (1-1
The tabularization of differentiation of random and
raster scan is as follows
1.8.1 Co-ordinates in Two
Dimensions
In a two dimensional system both
Random Scan Raster Scan the
axes aare
perpendicular to each other
having sing unit of
Random scan operate by The electron beam starts at
for both axes. length

directing the electron top left comer of the


The axis which is
beam to those parts of screen and moves
horizontal is referred as X axis and
only
the axis which is vertical
the sereen where the to the right.
is referred as Y axis, The
horizontally
common point where these two axes meet

|
is

picture is to be drawn. refered a


origin.

Creation of diagrams using Raster graphics can be To represent we


any point have to
specify it's both x
random scan becomes used in animation. and Y co-ordinate values.
Suppose a point P is
easier, so can be used in as (2, 3) then it will
represented interpreted as the value

engineering and scienific of X is 2 units and value of Y is 3 units.


drawings. So we have to plot a point P, 2 units away from the

Pen plotters and direct Cathode vertical axis and 3 units away from the horizontal
ray tubes (CRT) axis.

view ubes The details are shownin Fig. 1.8.1.


storage are used.

(DVST)devices are used.

The cost of devices used The cost of devices used


for random scan is much for raster scan is much
A'(3,2,0)
higher cheaper A"(0,2,1)
-A(3,2,1)
Requires less memory. Requires more memory.

Requires intelligent No such requirement.


A(3,0,1)
electron beam, i.e.

controlled.
processor

1.8 co-ORDINATE SYSTEMS Fig. 1.8.1

The common point of both X and Y axis is referred as

GQ. What a coordinateis system? origin, which is also sometimes called as starting point.
This set We
A co-ordinate system is a one which defines every
origin is usually to the value (0, 0). may
represent any point in any of the four quadrants. In first
point by a pair of numerical values, which are the
quadrant both X and Y values are positive. In second
distances from a fixed point in a perpendicular
quadrant X is and Y whereas
direction. To represent a coordinate we need reference
negative is
positive, in

line.
third quadrant both X and Y values are negative. In

fourth
quadrant X is
positive and Y is negative.
Each reference line is referred as an axis. The
where two axes are meeting is called as
These axes are perpendicular to each other.
its
point

origin. a 1.8.2 Co-ordinates in Three


Dimensions
i*.****************
One can use the same principle to specify the position GQ Howto *
** represent a point in three dimension system?
of any point in three-dimensional space by three co-
Coordinates for three dimensions is the extension
just
ordinates, its signed distances to three
mutually of two dimensions. Here we are having three major
perpendicular planes. In general, one can specify a
axes instead of two like in 2D system. In 3D we are
of any dimension.
point in a space having X, Y and Z axes are
axis. All these three

perpendicular to each other.

w.e.facademic year 20-21)(P4-28) Tech-Neo ure


(SPPU-NewSyllabus Publications...A SACHIN SHAH Ventu
Computer Graphics (SPPU-Sem.4-1IT) (Basic Primitives)...Page no(1-17)

In 3D usually X axis represents the width of the object. OpenGL requires the programmer
to specify
the correct Umt
Y axis represents the height of the
object and Z axis steps required to render a scene. Generally, penGL I
represents depth of the object. If we want to represent accepts points, lines and polygons, and then converts InSem.
any point in 3D we have to
specify (x.y.z) values of them into set of pixels by usingg the OpenGL state

that point. machine

1.9.1 OpenGL Architecture


(23)
(-3,1.1) GQ.
a*****
Explain OpenGl data processing operation.
ouoad* aa*u wo**-*****doodd**-******

To.q The Shows the block diagram of OpenGL


3 Fig.1.9.1

data processing method.

The commands enter from the left and proceed through

(-1.5,+2.5
a processing pipeline. Some commands specify

geometric objects to be drawn, and others control how


Fig. 1.8.2 the objects are handled during various processing

stages.
Suppose we represent a point A(3,2,1) then it means
point A is 3 units away from the origin in X direction, 2 Commands
Primitive Frame
Evaluator
units away from origin in Y direction and 1 unit away operaton
assemblyRasterizaltionP-ragment bufer

from origin
in Z direction. Point A(3,2,1) is displayed
in Fig. 1.8.2.
Texture

In 3D also we can have negative X or negative Y or


memony
Z axis we need to Display Pixel

.
negative coordinates. Accordingly
Ist operations

plot the specified point. In addition to this we are using


Homogeneous Coordinate system and Normalized 1.9.1
Fig.
Device Coordinate Systems also. These coordinate
will be seen in next chapters. The processing stages in basic OpenGL operation are
systems
asfollows
SyllabusTopic :Interactive Graphics Tool Display list Rather than having all commands proceed
OpenGL
immediately through the pipeline, you can choose to
accumulate some of them in a
1.9 INTRODuCTION TO OPENGL
processing later.
display list for

Evaluator The evaluator stage of processing provides


UQWrite ashort note on OpenGL.
an efficient way to curve and surface
(SPPU Q.5(b),May 18, Q 5(b), Dec. 18, 6Marks) geometry by evaluating
approximate

polynomial commands of input


UQ Explain OpenGL with respect to OpenGL operations. values.

May 19,6Marks)
(SPPU-Q.6(b)(OR), *-** Primitive
---****- ****- *****-******** assembly OpenGL processes geometric

OpenGL (Open Graphics Library) is a standard primitives points, line segments, and polygons all of

a and which are described by vertices. Vertices are


specification defining language platform
independent API for writing applications which transformed and lit, and primitives are clipped to the

generates computer graphics. viewport in


preparation for rasterization.

The interface consists of more than 200 different


Rasterization stage produces a series of frame-buffer

function calls which can be used addresses and associated values using a two
to draw different

complex 2D and 3D scenes. Rendering an object into


dimensional description of a point,
line segment, or
frame buffer is the main task of polygon. Each fragment so produced is fed into the last
OpenGL.
stage, per-fragment operations.

(SPPU-New Syllabus we.f academic year 20-21) (P4-28)


Tech-Neo Publications...A SACHIN SHAH Venture
(Basic Primitives)..Page no (1-18)

Computer Graphics (SPPU-Sem.4-1T) the mode where OpenGL


Feedback: This
is will
2.
the final
Per-fragment operations are operations
the geometric information to the
return processed
in the
rendering them
as pixels
performed on the data before it is stored
as compared to into frame
applications
frame buffer.
buffer.
conditional to
operations include updates
Per-fragment
It is used to create
the frame buffer based on incoming and previously 3. Alpha Bending: transparent

of
stored z values (for z buffering) and blending objects.

colors with stored colors, as well as


incoming pixel There are different operations
4. Pixel operations:
on values.
masking and other logical operations pixel
on such as storing, mapping, zooming,
carried pixels
form of rather than
Data can be input in the pixels
transformations, etc.

vertices. Data in the form of pixels, such as might


It is used to create realistic
describe an for use in texture mapping, skips the 5. Texture mapping:
image
we are
first stage of processing described above and instead is effects in images. In this process applying

as pixels, in the pixel operations different graphics primitives on images.


processed stage.

The pixel data is either stored as texture memory, for


Color index mode: Instead the
values
6. of storing
use in the or Rasterized, with the color indices.
rasterization stage; of RGB components color buffer stores

resulting fragments merged into the frame buffer just as

if were from geometricdata. 7. Polynomial evaluators It


supports NURBS
they generated

(Non Uniform Rational B-Spline)


1.9.2 Functions and Features of OpenGL In addition to above primitive functionality OpenGL
offers some of the important attributes /features also.
GQ. What are the different functions and features of

OpenGL? OpenGL features


**
There are many primitive functions provided by
1. Scaling and Rotation
OpenGL for graphics system. Some
of the important
graphics functions
of OpenGL are as follows: 2. Performance

Functlons of OpenGL 3. Transparency

1.Display list
4. Alpha Blending

2.Feedback
5. Rendering in 3D

6.Primitive
3. Alpha Bending
operations

7.Hardware
4. Pixel operations

Fig.C18: Features
ofOpenGL
5.Texture mapping
1.
Scaling and Rotation: The transformationslike
6.Color index mode scaling and rotation can be achieved very easily
without any
problem.
|7. Polynomial evaluators
2. Performance: Higher level
Fig. C1.7: Functions performance 1s
of OpenGL achieved when OpenGL is used
on an accelerated
device.
1. list: The
Display contents
of list are
display
and executed more 3.
preprocessed efficiently than the Transparency: We can make some or
same set of OpenGL commands executed in immediate the
graphicsas a portion
transparent area with the help or
mode OpenGL

4 Alpha Blending:It allows


semi graphics to be drawn
transparently.

w.e.f academic year


(SPPU-New syllabus 20-21) (P4-28)
LTech-Neo Publications...A SACHIN SHAH Venture
Computer Graphics (SPPU-Sem.4-1T)
(Basic Primitives)..Page no (1-19)
Rendering in 3D:
I
5.
OpenGL offers ability Unit
render 3D graphics. By using OpenGL we can draw
to
a1.9.4 OpenGL Library
the
objects which are away from the user as smaller as of
OpenGL provides a powerful but primitive set
InSem
to the objects which are near to
compared viewer. rendering commands, and all higher-level drawing
must be done in terms of these commands.
6. Primitive operations : OpenGL provides basic
drawing primitive operations such as point, line,
OpenGL provides a simple collection of utilities, called

polygon. etc. the GL Utility Library or GLU in short. Functions from


the OpenGL library begin with "gl", functions from
7. Hardware: Whenever the speed
of operation GLU begin with "glu", and functions from GLUT
needs to be increased, OpenGL use hardware. begin with "glut".

.
1.9.3 OpenGL Prlmitives and Attributes
We need to include the gl.h header file in each
program, for all
OpenGL applications. Almost all
OpenGL supports various basic primitive
types such as OpenGL use GLU
applications i.e.
line and polygons. Sequence of
OpenGL Uility
point, vertices is used to Library, which needs header file to be included in
glu.h
specify these primitives. There are ten different a program.
primitive
types. OpenGL interprets each primitive using following Because of this almost every
guidelines:
OpenGL source file starts
with
GLPOINTS: used to render a point.
#includeCLgl.h>
GL_LINES: used to draw unconnected line
segments.
Each group of two
#include <CUglu.h>
vertices are drawn by OPENGL.
If we are using GLUT to access window manager tasks,
GLLINE_STRIP: used to draw a sequence of then we should use :
connected line segments i.e.
joining the first and second
point then second and third and so on. #include <CU/glut.h

Where itself includes and


GL_LINE_LOOP: used to close the line
strip.
'glut.h' 'gl.h', 'glu.h', so
it is used to join the whenever we are using glut.h then there is no need to
Usually first and last
point.
include gl.h and glu.h
GLTRIANGLES: used to draw the individual
separately.

triangles. Triangle is formed from the three vertices.


OpenGL contains rendering commands but it is

designed as a and
GL TRIANGLE STRIP:used to draw a
sequence of
language operating system
independent. Because of this, OpenGL does not contain
triangles that share edges. Usually this is used when we
any commands to open a window or to read from the
need to draw a second and
triangle having first, third
keyboard.
edge followed by a common edge as second edge with
another triangle Since OpenGL commands are
drawing

:
i.e. second, third and fourth limited to
edge.
GLTRIANGLE FAN Whenever we need to share
generate simple geometric primitives such as points,
and polygons, GLUT includes several routines
lines,
edges as well as vertices we are making use of this
One
that create more complicated 3D objects.
primitive. of the common vertex is shared by al
the
triangles.
GLUT may not be ideal for all types of OpenGL
but we may it a
GLQUADS: used to draw a separate convex
applications, find useful starting point
for learning OpenGL
quadrilaterals. Whenever there are four vertices a
convex quad is formed.
a1.9.5 Programming Essentlals
GL QUAD_STRIP : used to draw a of
sequence
There are mainly five routines which
quadrilaterals which shares their perform tasks
edges.
GLPOLYGON: used to draw a
necessary to initialize
a window.These are as follows
solid convex
polygon. To use this the number of glutnit (int "argc, char **argv)
primitive vertices
and edges must be at
least three.
I Initializes GLUT and processes any command line

arguments

(SPPU-New
Sylabus w.e.f academic year 20-21) (P4-28)
Tech-Neo Publications...A SACHINSHAH Venture
(Basic Primitives)...Page no (1-20)
Computer Graphics (SPPU-Sem.4-IT)

Il glutInit()
should be the first GLUT routine. glutReshapefunc(ourReshape);
dimension for reshaped window
(unsigned int mode) /Gives new window
glutInitDisplayMode

color-index color model. glutMouseFune(ourMouse)


Specifies
We can also specify whether we need single- or
II Handles mouse button presses

double-buffered window. glutKeyboardFunc(ourKeyboard);


II Handles key presses
and releases.
gludnitWindow Position (int x, int y)
glutMainLoopPO: l to start event processingand
I Specifies the screen coordinates for the top- left
trigger display callback.
cormer of window.

glutinitWindowSize (int width, int size)


The call-back functions which we write are registered,
u Specifies the dimension of window.
and then the program enters in an endless loop, waiting
(char *string) for some events to occur. Wheneverany event occurs,
int glutCreateWindow
I Creates a window with a
specified string as a title of OpenGL calls the appropriate event handler function.

window
1.9.6 Event Driven Programmling
ghutDisplayFunc (void (func)(void)
It is an event callback In Event driven programming, programs respond to
function. This callback function
is executed when GLUT different types of events. The events can be of
key
determines that there
is a need

to redisplay the contentsof the window. press, mouse click or move, windows resize, etc.
So, we need to
Generally a system manages an event log or queue. To
gather all the routines which we need to redraw the
scene in the properly handle all such events, programmer provides
display callback function.
callback functions. To establish a connection between
dlutMainLoop(void) any event and its associated we must register
function,
It should be the a callback functions with
last command. Because of this OpenGL.
command,event processing starts, and the it triggers
We can use following instructions to callback
register
display callback. commands that gets triggered on the occurrence of
specified events.
Sample Program for first
OpenGL Program to open a
window: glutReshapeFune (void func)intw, int h))

#include <GL/gl.h>
W Tells about what to do if window size is
changed.

#include <CL/glut.h> glutKeyboardFunc (void func)unsignedchar key,


y)) and
int x, int
void main (int argc, char**
argv)
II allows us to link a keyboard key with a
specific
routine which is when a key is
glutlnit (&arge, argv);
triggered pressed or
1OpenGL toolkit initializes
released.

glutlnitDisplayMode (GLUT_SINGLE| GLUT_RCB);


glutMouseFunc (void (*func)(int button, int state, int
Setting display mode with single display buffer
x, int y))

glutlnit WindowSize (800,600); /nitializes window Iallows us


as 800 X 600 to link a mouse button with a
size specific
routine which is
triggered when a button is
pressed or
glutInitWindowPosition (100, 150); released.
I/ Initialize window's top left corner on sereen
glutMotionFune (void (func)int x, int y))
gutCreate Window("First Program"}; II Allows us to link a routine to be executed
I Assigns title of window as "First
when the
Program" mouse is moved with its button is pressed.

#Followingare the register the callback


functions
a 1.9.7 Keyboard and Mouse
Interaction In
gutDisplayF unc(ourDisplay); OpenGL
HRedrawsthe screen when window is
opened or
moved Keyboard and mouse are very
important input devices
rrom computer
graphics point of view. By using GLUr

(SPPU-New Syllabus w.e.facademic year 20-21) (P4-28)


Tech-Neo Publications...A SACHINSHAH Venture
Computer Graphics (SPPU-Sem.4-1T)
(Basic Primitives)... Pageno (1-21)
keyboard and mouse interaction becomes
extremely simple. release now in mouse we will be having button press Unit
For keyboard interface GLUT provides two different and button release.
methods namely for key press and
key release.
Following function allows us to link a mouse button ln Sem.
Key Press with a specific routine which is triggered when a button
is
pressed or released.
This method gives us information about the The syntax for
key the mouse event is as follows
currently pressed. The syntax of key press function is
as follows glutMouseFunc(myMouse);

void keyPressed where myMouse is a call back function which is


(unsigned char key, int x, int y) having
four parameters as follows:
The parameters for this
function contains key which is
void
pressed andX and Y gives information about myMouse(int x, int y)
button, int state, int
currently

the coordinatesof the mousewhen where button gives us information about which mouse
key was pressed.
We have seen one method
button is pressed i.e. left, or middle. right

which
already

is related
provided by GLUT - State tells about whether button
to
keyboard. That method is is
pressed or released
in state
gutKeyboardFunc(key Pressed);
X and Y gives the position of mouse when the event
Which TellsGLUT to use the method "keyPressed"
has occurred.
In main method, we will pass our keyPressed method
In to mouse
as a
parameter to the
addition button press or release, we are
glutKeyboardFunc method.
having some additional event also with respect to
In our
keyPressed method we may use switch mouse, which is referred as MouseMotion event.
command or 'if command which will check which
key Mouse Motion Event contains information about
is getting pressed.
current position of the mouse as we drag the mouse by
void keyPressed (unsignedchar key,int x,inty holding the button pressed.
:
In this
procedure the event generation is the continuous

f(key= *) procedure as we press mouse button and drag the


mouse.

/f the key pressed is 'x' then Execute the


required
The MouseMotionEvent is registered with GLUT by
routine following command

glutMotionFunc(myMovedMouse);
where myMovedMouse will be a call back method
which can be declaredas
Key Release void x, int y)
myMovedMouse(int
This of key release also handled in the same
function where X and Y will be the position of mouse on screen

way as that of key press function. The syntax of key


release function is as follows
Important Questions
void keyUp
(unsigned char key, int x, int y)
The parameters for this are very
Here we are mentioning some important
function similar to the
parametersof keyPressed function.
questions from the topic which we have seen. And
also, how to write the answers for these
Here also we need to link this method with GLUT We
are not writing the full answersfor
by questions.
using glutKeyboardUpFunc method. the questions, but we are insisting students to
This method write the answer in his/her own words. Here we
infornms GLUT to use the method
are providing guidelines for the answers. So that,
"keyUp" for event key release. Rest all the things will
be same as with the help of those guidelines or points, student
that of
keyPressed method. can write his own answer.

Mouse a.1 What are the different of Graphics


Event applications

system ?
Mouse event is
conceptually very similar to keyboard
event. Ans. The answer for such a question should includes
Only difference is instead of key press and key
followingpoints.

(SPPU-New
Syilabus w.e.f academic year 20-21) (P4-28) Tech-Neo Publications.A SACHIN SHAH Venture
Computer Graphics (SPPU-Sem.4-1T) (Basic Primitives)..Page no (1-22)
What is computer graphics? a.4 Explain display file and its structure.

How it is useful in different areas ? Ans.: Here we havetoexplain


How it can be used in our daily life ?
What is display file ?
Student must write at least 3-4 lines for each of the
Why it is required ?
above mentioned point.
What is its structure ?
Q.2 What are the characteristics of display
How the display file interpreter comes in picture
by
adapter?
using block diagram?
Ans.: The answer for this question should include the detail

characteristics
-Explain the display file by taking anysimple example.
explanation offollowing
Draw the diagrams wherever needed.
Resolution

Color depth Q.5 What is frame butfer ? How long would it take to

12
load a 1280 by 1024 frame buffer with bits per
Refresh rate
pixel if transfer rate is 1Mbps ?
Acceleration the
Ans. :Picturedefinition is stored in a memory area called

Q.3 Write a short note on any output device. refresh buffer or frame buffer. This memory area holds the

set of intensity values for all the screen points. Because


Ans.: Here we have to explain one of thefollowing device
eight bits constitute a byte, frame-buffer sizes of the systems
in detail
are as follows: 1280 x 1024 x 12 bits = 15728640 bits =
Monitor (both monochrome and color)
15.73 Mbits. Since the transfer rate is 1 Mbps and we need
Raster graphics display
to transfer 15.73 Mbits data we need approximately 16 sec.
Plotters

a.6 Consider a raster system with resolution of 1280 by


DVST
1024. What size of frame buffer is needed for given
Plasma panels
system to store 24 bits per pixel ?
Vector refresh display
Ans.: The frame buffer size is calculated as
While explaining any device mentioned above we have =3932 kB.
1280x 1024 x 24 bits /8
to draw a suitable diagram and explain the working of that
Since 8 bit constitutes a byte, the frame buffer size will
device. Also don't to mention the advantages and
forget
device. If possible mention the be 3932 k Bytes.
disadvantages of this

application
of that device also.

Chapter Ends...
O00
UNIT 1 Scan Conversion
CHAPTER 2
Syllabus
Line Drawing

Circle
: DDA
Drawing:Bresenham
Line drawing

circle
algorithm,

drawing
Bresenham Line drawing

algorithm.
algorithm

Character Generation : Stroke principle, starburst principle, bitmap method. Introduction to aliasing and anti-

aliasing.

2.1

2.2

2.3
Introduction

Line

2.2.1

2.2.2
and Line

Line
Segments.
Segments
Intersection of
.
Two Lines.

**************""********************"
********************°***********************"********************

*****************************************************

syllabus Topic:Line Drawing Algorithms. **°********°*******'*************"******


Line Generation Algorithms *******************************************************************nns
*******************

************a****t***eosstssdsatssossens.G
.2-2

Z-3

.2-3
.2-4

C
2

DDA Algorithm. *******


ssssmnne* **********************************************************************************************
2.3.1 *****2-5
2-7
2.3.1(a) Steps for DDA Algorithm...

2.3.1(b)

2.3.1(c)

2.3.2

2.3.2(a) Steps
Advantages

for
of

Disadvantages of DDA..
Bresenham's
DDA.

Line Generation Algorithm


Bresenham's Line drawing Algorithm for Gentle Slope (m<1).

Example2.3.18 (SPPU-Q.2(a), Dec. 17,Q. 1(b), Dec. 18, 6 Marks)..


.
*******

**** *********************************e*********************''*************"*********

***esneser*naseaeen*****
..
*s******
2-11
2-8

2-10

2-19

.
Example2.3.19 (SPPUQ. 1(a), May 17, 6 Marks).
2.3.3 Comparison of DDA and Bresenham's Line Drawing Algorithm. 2-21

2-21
Syllabus Topic:Circle Drawing Algoithm.
2.4 Circle Generating 2-21
Algorithms. ********

2.4.1 Midpoint Circle GenerationAlgorithm ********************************"**************** Z-22


*********************isesanaseea

2.4.1(a) Steps for Midpoint Circle GenerationAlgorithm..************* ****************************************************<


2-23

2.4.2 Bresenham Circle


Generation.. .2-25
2.4.2(a) Steps for Bresenham's Circle Generation Algorithm... 2-27
Ua. What are the steps of Bresenham's circle algorithm ? Explain with example.

(SPPU Q.2(a). May17,0.1(a),Dec.17,Q.1(a), May 18, 6Marks). 2-27


***************************************4

2.5 Aliasing and


Anti-aliasing..
*********** ******************************** 2-29
2.5.1
Aliasing.
** *********. * **n********************************** 2-299

2.5.2 Antialiasing. ********** *********************************************************************************. ****"' 2-30


*****
2.6
2.5.2(A) Antialiasing

Normalized Device Co-ordinates.


Methods.. *****"*******"******* ******
2-30 2-31

2.7
CharacterGeneration.. 2-32

Chapter Ends .. . ansent*****s eqnosene***********e**************"***************************************aanmugop*****n*********************** 2-388


Page no (2-2)
(Scan Conversion)..
(SPPU-Sem.4-IT)
Graphics
Computer
(K-32
(X2-X)

2.1 NTRODUCTION
i.e.y (%-x,) +y1
we have studied many display devices.
In last

To make
chapter
use of these devices
etc..
to display the objects

we need some special


like
Y- x+y
circle. polygons.
line.
be the procedure used,
But whatever may
the images by tuming the
procedures.
is generating
m b
the system
which the object is
pixels
ON or OFF. The process in
y m-x +b...slope intercept form
of discrete pixels is called
as the collection
represented

Scan conversion.

is a smallest element of the screen


Where m xX
Weknow that pixel

i.e. either On/Off. If we wish


b y1-mx
be controlled
which can
a point P(3.3. 5.5), then it means we want to Slopem is the change in height divided by the change
to display
We in width for any two points on the line. The intercept b
that pixel.
wbhich contains this point P.
iluminate
an integer is the height at which the line crosses the y-axis. We
can that point P\x. y) Is represented by
say
So we can use the can get y intercept by having (0, b). Refer Fig. 2.2.1. A
of and integer part of "y.
part
different form of line equation is called general form.
command as

Consider the Equation (2.2.2).


(int z. int y, Color);
purpixel

we use right
handed coordinate system,
Normally

bowever in case of computer system, the system turns

out to be left handed system.

22 LINE AND LINE SEGMENTS


X
We can specify a point 0,0
by giving pair of numbers (x, y)
where x represent horizontal distance and y represents Fig. 2.2.1
To specify a line we need two such
vertical distance. points.
(y2-Y)x-x) = (y-Y1) (a-x)
Every line is described by the equation such that if a

point (x,y) satisfies the equations,then that point is on


(-Y1)x-(2-X)y +X2y1 -X Ya=0
the line. If the two points rx +sy +t = 0 .2.2.3)
used to specify a line are

( Y) and (a2y,) then the equation of line will be, Here possible values of r, s, t are,

(2.2.1)
t
Ya-Y S- (X2X1)
X2 y1 -X1 Y2
This equation says that the slope between any point on
the line and
If we compare Equation (2.2.3) with slope
point (x.y,) is the same as the slope between intercept

Y) and ( form i.e. y =mx +b


Y).
There are
many equivalent forms for this rx+sy+t = 0
equation.
Multiplying by denominators we get, sy =-IX-t
-Y)-x,) =(Va-y) (%-x,)
by solving this for y,
(2.2.2)
y -x-
-y)= E-z)
a-X) m b

'm =and and b=-


SPPU-New Syllabus w.e.facademic year 20-21)
(P4-28)
Tech-Neo SHAH Venture
Publications..A SACHIN
Computer Graphics (SPPU-Sem.4-T)
(Scan Conversion) ...Page no (2-3)
a 2.2.1 Line Segments
2
Unit

GQ DefineLine
-
Segment.
****--*
I
*******a-* *********. InSem
There is a difference between line and line
segment. Y1

The lines can extend forever both forward and


backward. But in graphicswe would like to display
only a piece of lines. Let's consider only those
points
on a line which lie between two end points Pj and Fig. 2.2.3
P2
See Fig. 2.2.2. This is called line segment. 2.2.2 Intersection of Two Lines

GQ.How to find out intersection of two lines?


***
We can determine a point where two lines can cross.

By two lines
crossing we mean they share some
Fig. 2.2.2
common point. That point will the equations for
A line
segment may be specified by its two end points.
satisfy

the both lines.


From these end points we can determine the equation
of the line. If the end points are P, = (3,y1) and Suppose there are two lines line 1 and line 2 and both

P =(a)and these yield equation y =mx +b then


lines are intersecting at point (x, y). Then we can

another point P= (13.y3) lies on the segment if representline 1 by equation,


y =m x+ b, and equation forline 2 as
mxg+b =m
Xg is in between xj and x2.
y X+ b2

Line 1

y3 is in between y, and
y2
There is one more useful form of the line
equation
called the parametric form.In this
y-values case x and Line 2
on the line are given in terms of a
parameter u. Suppose Fig. 2.2.4

we want the line segment between (x1. y,) and (2, Y)»
then we need the x co-ordinate to move
Where, m and m, are slopes of line 1 and line 2
uniformly from respectively. If point (x,y) is shared by both the lines then
to x.This may be the
X expressed by equation, the point
(x Y) must satisfy both the line equations.

wbere u =0 to 1
m+b, Equating both over
and y,=m4+b
y.
When = 0, x =x. As u
uniformly to
u

x. we must have
increases to 1, x moves
m X +b m X +ba
Similarly the y co-ordinate
m X-m X;
= ba-b,
moving from y, to y, at the same time as x changes.

y Y1+(-Y,)u (2.2.4)
m-m2
to find the length of line
Similarly
segment we can Equating the value of x;
in any one line equation we
make use of
Pythagorean theorem. See Fig. 2.2.3. will get y; as,
Suppose point P, is (x.y,) and is (xz, Now if we P
want to find
length (L) of line segment P, P2 then
y).
Yi m,x+b=m,| +b,
L' = (-x,)' +(2-y
mb,-m b
L =V-x,+ (Ya-Y m-mn2

Similarly we can find midpoint of a line segment very mb,-mb+ m b-m,b


m-ma
easily.

y -mb
m-m

(SPPU-New Syllabus w.ef academic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
(Scan Conversion)..Page no(2-4)
Computer Graphics (SPPU-Sem.4-IT)

b,-b 29| is intersection point.


point m,m2

Syllabus Topic:Line Drawing Algorithms

M 2.3 LINE GENERATION ALGORITHMS

the of good line generation


are
GQ. What qualities
Fig. 2.3.1

algorithm?

means we have to But it will not be easy to find all such pixels and when
draw a line that
When we want to

ON condition i.e. we have to we are using line drawing for big project or in
make the pixels on that line to

on that line. animation where picture may change frequently, in that


of the pixels present
change the intensity
case it is very inefficient.
should have following
A good line drawing algorithm
So the alternative way for this is to
step along the
qualities
both end columns of the pixels and for each column finalize
It should a line considering points.
generate
which row is closest to the line. We could then turn ON
It should urn ON maximum number of pixels which
the pixel in that row and column.
lies on the line

It should generate
smooth line.

M=1 N= 0 M=-1
It should be applied
to all
type of lines i.e. lines
having
different slopes.

It should reduce number of calculations. 45

It should be fast and accurate.

(a) Gentle slope lines


It should consume less memory.

To generate the line we are having two different

algorithms.

Line Generation
Algorithms

1. DDA (Digital Differential Analyzers)


ww.wwwe ******
(b) Steep slope lines
2. Bresenham's Line
Drawing Algorithm Fig. 2.3.2

Fig. C2.1: LineGeneration Algorithms


We know how to find the row because we can
place the
x-value corresponding to the column into the line
Both the algorithms are based on increment
method
equation
and solve for
Let us see this increment y. This will work for lines with
slopes between
method now. - 1 and 1
(i.e. lines which are closer to horizontal
To draw a line we must know the lines).
two endpoints. Here Such lines are called as lines
with gentle But for
we are
selecting the which lie near the
slope. steep
pixels line slope case it will leave gaps. So we
segment. See 2.3.1.We could step along the rows and
Fig. to on the
try turn solve for the columns.
Fig. 2.3.2 shows different lines.
pixels through which line is
passing.
Forgentle slopes (-1 <m<
1) there are more columns
than rows. These are
the line
segments, where the
length of thbe x component, Dx = -
(x, x,) is longer than
the y
component, Dy = -
(y, y), i.e. Dxl > For Dyl.
this case we step across the columns and solve for the
rows. See Fig. 2.3.3.
Computer Graphics(SPPU-Sem.4-1T) (ScanConversion)..Pageno (2-5
As there are more number of columns than rows and This means that as we step along the columns, we can Un
we are moving along columns we are getting more new value of the line by just adding m or
find the y for
number of pixels i.e. on every column we column. See
are getting slope to the y position at the previous ln Sem.
somepixel. So it will not leave gaps. 2.3.4.
Fig.

For the sharp slopes where IDxl Dyl, we across

the rows and solve for the columns. See Fig.


step

2.3.3.
2.3.1 DDA Algorithm
Digital differential analyzer is based on incremental
method. The slope intercept equation for a straight line

18,

y = m x+b
Where m and b We can
Dx determine the value of m
is slope

as,
is y-intercept.

m
Gente slope

2.3.3
Sharp/ Steep slope
-X1
Fig.
y -Y1) is nothing but change in y-values which is

as Dy.
Consider the gentle slope case where we step across the represented

columns. Each time we move from one column to the Similarly (x-X1)is represented as Dx.

the value of x 1. But if x


next,

changes by exactly
changes by
1, then
always
by what value y should
.m
change? Answer is, y will always change by exactly m
(the slope).

we
How? Let us say
are considering
y,) is starting

gentle
(x
slope case means
point.

we
As
are
2
moving along columns i.e. x-axis, next point will be on
column (x+ 1).

If
what
( will
y) = (2,
be (y,
3) then

+ 1), that
x+1 =2+ 1
we have to
and
find out.
at that

When we
time
Dx

are saying that


(x, y,) is starting point means (x, y)
satisfies equation of line i.e. y,
= mx, + b. Now we Fig. 2.3.5

know (x,+ 1) and for that we have to find out (y,+ 1) in Refer Fig. 2.3.5. For lines with slope (m) is <1
i.e. lines with positive gentle slopes, we are moving in
such a way that (x,+ 1,y, + 1) will satisfy the equation
X-direction by uniform steps of calculating the
ofline i.e. y,+ 1 = m (x,+ 1) +b.
corresponding y-value by using

Dy
Dx

(y.+1)-(y)
Dy= m Dx
= m. [ (x,+ 1)-(x)]

along x-axls
Moving

Fig. 2.3.4

(Y+1)-yi = m (x,+1)+b- mx, -b


= m [(x+1)-x]=m (1)=m
Xa Xat1

Fig.2.3.6

(SPPU-New Syllabus w.e.facademic year 20-21) (P4-28) ATech-Neo Publications..A SACHIN SHAH Venture
Computer Graphics (SPPU-Sem.4-1T
(Scan
Conversion)...Pageno(2-6)
But as we are moving in x-direction
by 1 unit

ie. distance between two columns:

(,+1)-(,) = 1. See Fig. 2.3.6

(y+1)-(y,)=nm (1)

i.e Ynew Slope + yold (2.3.1)


Similarly when the slope is > 1 i.e. lines with
Fig. 2.3.8
positive
steep slopes, we are moving in Equation (2.3.1) and are based on
y-direction by uniform steps
(2.3.2)
assumption
and the that lines are to be from left end
calculating coresponding x-value. See Fig. 2.3.7. processed point to

right side

Dx m i.e. is reversed
Xgtar Xend lf this process i.e.
xgartXepd
then

i.e.Dx
=Dy
YnewYold-m and XnewXoldm
(+1)-a) = +)-(y)
m Since slope (m) can be any real value (floating point
number) between 0 to 1, the calculated y-value for
Gentle slope or calculated x-value for steep
slope must
be rounded to the nearest integer, because display
device is as integer
having co-ordinates
only. See
Ya1 Fig. 2.3.9.

Ya

rows.
But [(y,+ 1)-y)] is

,+1)-x) =
Fig.

1
2.3.7

unit i.e. distance between two

y
y2
1

L
X=1 x=2 3

Fig. 2.3.9
4 5

x+1 +X We can represent integer point as (2, 3) but we cannot


represent any fractional point as (2.3, 3.1). Sowe need
1.e.
Apew
slope + Xola
.(2.3.2) a
separate function which will round that float value to

For
When the slope (m) is = 1 then as x changes, values of
integer.

functions are used.


this
generally ceiling and flooring

y also changes. See Fig. 2.3.8.


Ceil: This is a function which returns smallest integer
i.e. Dy
Dx m which is greater than or equal to its argument.Suppose
the value is 8.6 and if we are this value to ceil
but m = l
function then that function
passing

will return 9.

Dy= Dx Floor: This is a function which returns largest integer

Ynew Yold+1 and *new which is less than or equal to its If the value
Kold + 1 argument.

is 8.2 and if we are passing this value to floor function


then it will return 8.

There is no doubt that because of this floor and ceil

functions the point is diverting from actual location.

(SPPU-New Syllabus
w.e.f academic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Veture
Page no (2-7)
(ScanConversion)...
Unit
Computer Graphics (SPPU-Sem.4-1T)
and y, > Ys

a 2.3.1(a) Steps for DDA Algorithm


8. Similarly

Then the
if IDxl<IDyl

values of increments in x and y-direction


are
lu
I
Sem.

Write steps for DDA line drawing algorithm?


GQ.******* ********iao and-1.
end : (X,. and
Accept two points y,) (xp. yh)
Refer Fig. 2.3.13.

Find out horizontal and vertical difference between end


2.

3.
Dx AX
points.

Difference between
and Dy
greater
= yh
- y.

magnitude determines the


X Increment

Increment-1
m

value of parameter steps.

4. Determine the offset needed at each step i.e. to generate


a
this step times.
the next pixel loop through Fig. 2.3.13

and < Then the values of the


IDxl> generation
Program for DDA
5. If IDyl x, Ap, line
2.3.1:
Program
in the x and y-directions
are 1 and mn
increments
See
********N********s***#********n***********
respectively. Fig. 2.3.10.

incrementl
Program:C program to draw a line by usingDDA line

Yincrement
m generation
algorithm

#include<iostream.h>
#'ncludeconio.h>

#includemath.h>
Fig.2.3.10
#includestdlib.h>
the decrements -1 and .
-
..
and x,> x, Then
6. IfIDxl>IDyl #include<dos.h>
m are used to new point.
See Fig. 2.3.11.
generate #include<graphics.h>

increment-T void dda(int xl,int y1,int x2,int y2);

and yincrement
2-I
a Main
Function Name
Purpose To initialize graphics mode and eallDDA

a function

Fig 2.3.11

< IDyl and y, <y» void main)


7. Similarly if IDxl

x and are
Then the values of increments in y-direction
int gd DETECT, gm;*detect the graphics drivers

1/m and 1
respectively.
automatically*/
Refer Fig. 2.3.12.
intxl,yl,x2,y2;
/Initialise to
initgraph(&gd,&gm,"'orlltcpluslbgi");

increment m graphics mode


= 1
cleardevice0:
Y incremernt cout<" DDA Line generation
"
cout< n enter the starting
algorithm";

co-ordinates for drawing

line"';
Fig. 2.3.12
cin>>xl>>yl;.

(SPPU-New Syllabus we.f academic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
tn
cin> >2>>>12.
entrr iheending nvvhsnales
Output

DDA Line generatíon algorithm

en-nrelinaten for drawing line


da 1,2,12. Fnter the atarting

cout "n Thand m 2)


gch):
enler the ending en-ordinatea
doregph0
450
400

Function Name dda Thank you

Purone :Todrava line using DDA

akgorthm

vaid ddeint ndint ylint 2iat y2)

int icddy,steps;
loat Advantages of DDA
2.3.1 (b6)
doat xincyinc; *******
DDA line
dx (x2-xl); GQ. What are the advantages of drawing

d-(2-): algorithm?

ebeidaj>=abs(dy} decide whether to move The DDA a method for calculating


L algorithm is faster

alon use of line


pixel positions than the direct equation

direction

steps dx; or y-direction


/ y mx +b. )
It is to understand.
very easy
for implementation.
eps =dy
requires no special
It skills

xine=(oat)dx/steps;/calculate

yineoet)dy/steps;
the increment
2.3.1
****
GQ. What
-
(c) Disadvantages of

are the disadvantages of


DDA

DDA line drawing

algorithm?7

Because of round off, errors are introduced and cause

putpisel (xy,WHITE); plot first point/ the calculated pixel position to drift away from the true

for (i-listepe;it+ *) line path.


is
Because of the algorithm
floating point operations
X+xinc;
y* yinc
time-consuming.

Example 2.3.1 Plot a line using DDA line generation


convertdhe floating value to its neareat integer value.
algorithm from (1, 1) to (5, 3).
ie, same as use of ioor or ceil function *
xl +0.5 Solutlon:
yi= y40.5; Here we want to draw a line from (1, 1) to (5, 3).

putpixel (xd,yl,WHITE}; /* plot the points So,x= 1, y1


= 1, X2
=5 and y, = 3.

Dx (x^-X)=(5-1)=4
Dy (a-y)=(3- =2 1)

As IDxl>IDyl the line is


of gentle slope category.

academic year 20-21) (P4-28)


SPPU-New syllabus
w.e.f
Tech-Neo Publications..A SACHIN SHAH Ventue
Computer Graphics(SPPU-Sem.4-1T)
(ScanConversion)..Page no (2-9)
Steps =

increment
abs (Dx)

D=0.5
steps
=4
As IDxl> 1Dyl

:the line is of gentle slope category

Steps=

Increment
abs (Dx) =4 I
Unil

n Sem.
Yincrement steps
steps

First point we know i.e. X. y, so plot it.


YIncrement
steps

new Yold Xincremen


+1 =2 First we know i.e. 6o it.
point X1. y, plot

new Yotd Yincrement +0.5 = 1.5


ne Kold + increment5 + 1 =6
But over here we have to round off 1.5 as 2 for Ynew Yold YIncrement
displaying that point.
= 8+(-0.75) =7.25
For next iteration
But over here we have to round off 7.25 as 7 for
new old+Xincrement 2+1 =3 displaying that point. For next iteration
Ynew
Yatd Yincrement1.5 +0.5 =2
new ¥old +Xincrement=6 + =7 1

Now loop steps are tabulated as follows


Ynew Yold + Yincrement= 7.25+(-0.75) =6.50
Plot Now as follows:
loop steps are tabulated

332 3,2
22
4425-34,3
1.5-2
1,1
2,2 5L
2|6 7.25-7 6,7
85.8
Plot

535,3 37 6.50 7 7,7

6
For
for display

If
calculation

we
only,

do
we are
this
purpose

till
xpew
we are
rounding the values
and ynew
using original

becomes same as end


value but

Example
s
2.3.3: Consider
9

the
5.75

line from
8,6

9,5
(0, 0) to (-6, -6).
we will sameas shownin Use the simple DDA algorithm to rasterize this line.
point then get line
Fig. P. 2.3.1.
Solution
Suppose if we want to draw a line from (0,0) to

(-6,-6).

So, x =0, = y1 0, x2=-6 and y,= -6.

D = x2-X) = (-6-0)=-6
D, a-y)= -6-0)=-6
Lets plot 1" point as (0, 0)
Ol112 l3|4 |6
Since D, = D, the line is in gentle slope category.
P. 2.3.1
Fig. It means we have to move along x direction from x, to
and
Example 2.3.2 Explain DDA line drawing algorithm
find the corresponding y value.
in Xa

detail. Can line segment represented by points PI (5, 8) and


P2 (9,5)be drawn using DDA algorithm ? Explain.
After plotting

.
1" point as (0,0) increasexby

=
1.

, Steps abs (D,) =6


Solutlon
Suppose if we want to draw a line from (5, 8) to (9,5). Aincrement =-6/6-1
steps

x5.y8, =9 ys=
Dx
So,

-X1)=(9-5)=4
and 5.

Yincrement 6/6=
D,
steps -1
Dy= (Va-y)=(5-8)=-3 First point we know i.e.
X, y1 so plot it.

(SPPU-New Syllabus we.f academic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
mputer Graphics (SPPU-Sem.4-1T) (Scan Conversion)..Page no (2-10
.Anew

new
old Xincrement0

Yold+Yincrement=0
+(-1)=-1

+(-1)=-1
XY
1 1,1
Plot

For next iteration 1.8 2 2,2


3 3,3
2.6
new Xold +Xincrementl+(-1)=-2
3.4
4 3,4
new Yold+Yincrement-1+(-1) -2 =
Now follows
4.25 4,5
loop steps aretabulated as

Plot
56|5,6
2.3.2 Bresenham'sLine GeneracionAlgorithm
0,0
one more algorithm to generate lines which is

-1 There is

4
2
-3 3
2-2
-3,-3
called

between the
called
as Bresenham's

error
actual

and it is
line
line

denoted by G.
algorithm.
and the nearest grid
The distance

location is

line is as shown in Fig. 2.3.14. After


-4 -4,-4 Suppose
first point (0,0)
we have to select next point
displaying
5 -5,-5 (1, 0) and (1, 1).

7 there are two candidate pixels


Now
we have to select one pixel.
-6,-6 Out of these two pixels

Example 2.3.4 Explain


DDA line drawing algorithm.

Consider the line from (1,1) to (5,6). Use DDA line drawing
to rasterize this line.
algorithm

Solution:
=6
Given:x, = 1, Y, = 1, x2 =5, Y, Fig. 2.3.14
Dx= X^ -X1 =5- 1 =4
This selection of pixel will depend on the slope of the

Dy= y2-y1 =6- 1 =5


line. If the slope of line is greater than 0.5 then, we are
Since IDy I>IDx l the line is
of steep slope category selecting upper pixel i.e. (1, 1) and if slope is less than

Steps = abs (Dy) =5 0.5 then we are selecting next pixel as (1,0).

Dx =0.8 As we are interested in only checking whether the point


increment Steps is below 0.5 or above 0.5, we will put condition as if

slope of line
the is greater than or less than 0.5.
Yincrement Dy-=1
Steps
Example
As we know 1" point, let's plot it as (1, 1)
Suppose the slope of line shown in Fig. 2.3.15 is 0.4.
new Xold +Xincrement
1
+0.8 = 1.8 After displaying 1" point as (0, 0) we will add slope of line
I+l =2 G become As we
YnewYold+Yincrement to error factor G, so that will 0.4. are

But here we need to round off 1.8 as 2 for displaying considering gentle slope case we are moving along x-axis so

that point next pixel will be x = and 1 at that time y will be decided by
G. If G> 0.5 then y = 1 else y = 0. But here as G 0.4 so
for next iteration

we have next point as (1,0).


Anew oid+increment= 1.8 +0.8 =2.6 to select

Ynew Yotd + increment =2+1 =3


Like this we will calculate points
till yaew becomes

to y2 i.e. 6
equal

The following table summarizes the points.

Fig.2.3.155

we.f academic year 20-21) (P4-28) Tech-Neo Publications.ASACHN SHAH Venture


(SPPU-NewSyllabus
Computer Graphics(SPPU-Sem.4-1T)D Conversion)...Page no (2-11)
(Scan
Again for next point x is increased by 1 and it becomes If we further solve this equation then we will get
Unit
x# 2, for that G will become G G+m ie. 0.8. Now G = G+2 Dy 2.3.6)
this time G>0.5 so upper pixel is more near to desired In Sem.
we consider
why we
if
one. That is have to select
Similarly
upper point
i.e. (2, 1).
P = P+ slope - 1, then
The beauty of Bresenham's is is
We will get
algorithm it

implemented entirely with integer numbers and the G G+2 Dy -2 Dx .2.3.7)


integer
numbers are much more faster than floating- To calculate this G we need addition and
only
point arithmetic. But in previous section we have seen subtraction and no multiplication or division. Another
we are checking slope with 0.5. i.e.
that
floating point thing is now, this G is not containing any fractional part
variable. So how we can make use of integers for this also.

test?
So, we can use test G> 0 to determine when a row
For Gentle slope case
boundary is crossed by a line instead
of P> 0.5.
Consider P as height of pixel or error. Our condition is As the initial value of P is so we have to find
slope,
whether P>0.5 or not. initial value of G also. We know from that
Equation (2.3.5)
f P> 0.5 2.3.3) G = 2DxP - Dx
But here 0.5 is floating point so we have to conver Put initial value of P as Dy/Dx to find initial value of
floating point to integer. For that we will multiply both sides G.
by 2.
G 2Dx X-Dx
2P-1> 0 ..(2.3.4)

In this equation we have removed fractional


part 0.5.
G 2Dy -Dx
But still it may contain fractional
part from the For each column we check G. f it is positive we move
denominator of slope. Because every time we are to the next row and add (2 Dy -2 Dx) to G, because it

updating P by. is equivalent to P =P + slope 1, otherwise we will

and add (2 Dy)to G.


P P+slope keep the samerow

or P P+ slope -1
2.3.2(a) Steps for Bresenham's Line drawing
we are adding
i.e. here
slope toP Algorithm for Gentle Slope (m < 1)
Dy
But slope is nothing but
GQ.What are the steps for Bresenham line drawing
So the fractional part may come due to Dx. To algorithm ? *i--iS->iu
eliminate this we will multiply the Equation (2.3.4) by Dx.
1. Accept two endpoints from user and store the left&

2PDx -Dx > 0 endpoint in (xg» Yo) as starting point.


Now we will G=2 PDx-Dx
define .(2.3.5) 2. Plot the point (Mo» Yo
Our test will become as G>0 3. Calculate all constants from two endpoints such as Dx,
Now we will see how this G can be used to decide Dy, 2Dy,2Dy -2Dx and find the starting value for the
which row or column to select. G as G 2 Dy -Dx.
As G 2 PDx-Dx 4. For each column increment x and decide y-value by

G+Dx = 2PDx checking G >0


condition.
Ifit is true then increment y-

Now if
G+D
2 Dx
we consider P
P
=P+ then
value and add (2Dy

otherwise add (2Dy)


Plot next point. See Fig.
to
-
2Dx) to current value of
G and don't increment
2.3.16.
y-value.
G

slope,

We will Dx G+ Dx Dy
Dx
get
2 Dx 2 Dx

(SPPU-New
Syllabus we.f academic year 20-21) (P4-28)
Tech-Neo Publications..A SACHINSHAH Venture
(Scan
Computer Graphics (SPPU-Sem.4-1T) Conversion)..Page no
(217
void main

int gd
= DETECT, gm;
int xl,y1,x2,y2;

initgraph (&gd,&gm,"c:\tcplusllbgi");

cleardevice0;

Fig. 2.3.16 cout"Bresenhams line drawing ";


5. Repeat step 4 till Dx times. cout<< "n enter the starting point's co-ordinatesforline'
For slope cases just interchange the of x and
steep rolls ein>>xl>>yl;
yie. we step along y-direction in unit steps and calculate cout<"n enter the ending
points co-ordinates";
successivex-values nearest the line path.
cin>>x2>>y2;
If the initial position for a line with positive slope is
bresen(xl,yl,x2.y2);
endpoint, as shown in
right
Fig. 2.3.17, then we have to cout"n Thankyou";
decrease both x and y as we step from right to left.
getcho

XoYo closegraph0:

Function Name bresen


Fig. 2.3.17
Purpose To draw a lineusing bresenham's line
Program 2.3.2
Program for Bresenham's line drawing algorithm
generatioon

void bresen(int x1,int


yl,intx2,int y2)
Program
AC program to draw a line by
usingBresenham's line int
sl,s2,exchange,y-X,1,|
generation algorithm loatdx,dy.g,temps
dx abs{x2 -xl);
.
dy abs(y2 -yl);
#includeiostream.h>
xxl;
#includeconio.h>
yyl;
#includemath.h> sl=sign(x2-xl);
#includestdlib.h>
s2 sign(y2-y1);
#include <dos.h>
depending on the
interchange dx & dy
slopeof the line *
#include graphica.h>
i(dy>da)
yoid bresen(int xl,int yl,int x2, int
y2):
int sign (float arg);
temp dx;

..
dx = dys

Function Name Main


dytemp
Purpose
. To initialize graphicsmodeand
exchange i
callBresenham function
else

exchange =0
(SPPU-New Svllahus wefaradamir
2*dy-d
Computer Graphics (SPPU-Sem.4-IT) (ScanConversion)...Pageno (2-13)
i= 1 For horizontal Unil
Special cases can be handled separately.

whilei<=dx) lines we should not increase y.


We have to
just
x by In Sem.
increase/decrease 1
every time till endpoint.

putpixel(x.y,WHITE); For vertical lines we should not increase x we haveto

delay(10); just increase/decrease y by 1 every time till endpoint.

while(g>=0) Similarly for diagonal lines we will increase/decrease

both x and y by 1
every time till endpoint.

if(exchange ==l)
Example 2.3.5 Plot a line by using Bresenham's line

x=x+sl; generation algorithm from (1, 1) to (5, 3). See Fig. P. 2.3.5.
else
Solution:

ifexchange=l)
yy+s2;
8 8+ 2dy -2dx;
.
.
Given

Dx= X2-X =4
Dy Y-Y1=2
X1, y=1x =5, y2=3

y y+s2; G 2Dy -Dx = 2 (2)-4)


else G =0
x xtsl;
88+2*dy;
i++

Fig. P. 2.3.5
int sign(loat arg)

Plot 1 point (1, 1) here as IDxl> Dyl that means line is

Gentle slope, so here we have to move on x till x, i.e. 5.


if (arg <0)
return After plotting 1" point as (1, 1) increase x by 1

x=
-1;

else if(arg==0) 2
return 0; Here G = 0
else return l; We have to increase y by 1 and update G as,
G+ 2 (Dy -Dx) =0+2(2-4)= -4

:
G
Output So, plot next point as (2, 2) then again increase x by 1.

Bresenhams line drawing


Now it will become x = 3.

Enter the starting point's


co-ordinates for line drawing
Here G=-4.
200 y just update G
increase only as
So, don't
200 G G+2Dy =-4+22(2)=0
enter the ending pointe co-ordinates
So, plot (3,
x
2) goon doing this till reaches to x
250
We will get points as,
450
..
. .
.
,
Thank you

(SPPU-New Sylabus we.f academic year 20-21) (P4-28)


Le Tech-Neo Publications.A SACHIN SHAH Venture
(Scan Conversion)..Page
no(2-14
Computer Graphics(SPPU-Sem.4-1T)
Consider from (2, 7) to (5,
be in Example 2.3.7: the line 5.t

Fig.
So, the
P. 2.3.5(a).
final points
on line will as shown
Bresenham's line drawing algorithm to rasterize this ie
Solution:
Given:X =2, Y =7, K,=5,ya =5
Dx= ix-x,l= 15-21=(3)
Dy
=15-71=(2)
lya-y,l

G 2Dy- Dx =2 (2)-3 = 1

Plot (2, 7)
1 point
Fig. P. 2.3.5(a) Since IDxl> Dyl the line is having gentle slope

Bresenham is much more efficient than So we have to move along x till


x i.e. 5; after
ploting
algorithm

1" point as (2,7), increase


x by 1.
DDA, and

x =3
it only only addition
requires integers requires

and subtraction
operations

Example 2.3.6: Consider the line from (1, 1) to (6, 4). Use Here, G>0
Bresenham's

give output
line

pixels.
drawing algorithm to rasterize this line and
We have to decrease y by 1 because y> y2 and update

G as
Solution
Given: = y1=l
x, 1,
G G+2(Dy -Dx)= 1+2(2-3)
1+2-1) =1 -2=-1
. X2=6, Y2=4
Dx = X2-X1 =5
Dy Now
Plot the next point as (3,6)
again increasing x by 1, x becomes 4; here G=-1
ya-Y1 =3
G 2Dy - Dx 2(3) = -(5) Don't modify y and update G as

1 G =G+2Dy =-1+2(2) = 3

=
G
Plot
1 point (1, 1) here as IDxl> IDyl that means line is So, plot next point as (4,6). Go on doing this till x
Gentle slope, so here we have to move on x becomes xX2
till x, i.e. 6.

After ploting

Here
2
G>0
1" point as (1, 1) increase x by 1
:. Here the points

X Y
we are getting will be

We have to increase y by and update G as, 1

G G+2 (Dy -Dx) =1 +2(3-5) =-3


So, plot next point as (2, 2) then again increase x by 1.

Now it will become x =3.


Here G-3. Example 2.3.8 Explain Bresenham's line algorithm and
find out which
pixels would be turned on for the line
y just update G
So, don't increase with
only as end points (5, 2) to (8,
4) using the same.
G =G+2Dy=-3+2(3) =3 Solution:
So, plot (3,2) go on doing this till x reaches to
x2. We Given
will get points as,

X 5, Y=2
Xa 8, Y2=4
Dx=X2-X1 =3
Dy Y2-Y1 =2
G 2Dy- Dx =2 (2) - (3) =

.
1

Plot I point (5,2)here as IDxl> Dyl that means line 5


Gentle slope, so here we have to move on x till i.e.
x2

(SPPU-NewSyllabus w.e.f academic year 20-21)(P4-28)


Tech-Neo Publications.A SACHIN SHAH Ventue
=
Computer Graphics (SPPU-Sem.4-1T

After plotting 1 point as (5, 2) increase x by Now again increase


(Scan Conversion)...Page
x by 1, x becomes 7,
no(2-15)
Here G =3

I
Unit

1
6 i.e. G>0
> y2 and modify G as
In Sem.
Here G= 1
update y - by
1 because y1

We have to increase y by 1 and update G as, G G+2(Dy -Dx)


G G+2(Dy-Dx) =1+2(2-3)=-1| 3+2(2-3)
So. plot next (6.3) then
point as again increase x by 1. =3+2(-1) = 1

Now will become x = 7.


it
Plot next point as (7, 7) which is our another end

Here G1. point. Hence we get following points


on line (4, 9) to (7,9)

So. don't increase y just update G only as as,

G = G+2 Dy =-1+2 (2)=3


So. plot (7, 3)go on doing this till x reaches to x. We
will get points as.

6
Example 2.3.10 Using Bresenham's line find
3 algorithm,
out which pixel would be turned on for the line with end
8 points (4, 4) to (12,9).

Solution:
Example 23.9:Consider the line from (4, 9) to (7, 7). Draw
Given X =4, Y1 =4, X%
= 12, y2 =9
a line using Bresenham's line drawing algorithm.

Solution:
Dx= x2-x,l=112-41= 8
Given:=4, =9, x2 =7, y2=
y, 7 Dy ly2-Yil
= 19-41 =5
Dx =b-xl=7-41= 3 G 2Dy-Dx =2(5)-8 =10-8 =2
Dy =lya-yl=7-9= 2 Let's plot 1" point as (4,4)

G 2Dy -Dx 2(2)-3 =4-3=1 = Since, IDxl > Dyl the line is of Gentle slope category

So we have to move along x till x2 i.e. 12


Let's plot 1" point as (4, 9
Dxl> Dyl the line is of Gentle
Since slope category, so After plotting 1" point as (4,4),increase xby 1.

we have to move alongx till x, reaches. x becomes equal to 5

After potting
1" point as (4, 9) increasex by 1. Here G>0
5 So update y by 1 and modify G as
Here G > 0 G G+2(Dy-Dx) =2+2(5-8)
Soupdate y by- 1 because y, > ya and modify G as 2+2(-3)
G G+2 (Dy-Dx) =2-6 -4
=1+2(2-3) =1+2(-1)=-1
Plot next point as (5,5)

Plot next point as (5, 8) Now again increasing x by 1, x becomes 6, Here G=-4
Now again x by 1, x becomes 6. Here G=-1 Don't modify y and update G as
increasing

Don't modify y and update G as


G = G+2Dy =-4+25)
G G+2Dy =-1 +2(2) =-1+4 =+3 = -4+ 10=6
Plot next point as (6, 5).
Plot nextpoint as (6, 8)
Go on doing this till x becomes xq

(SPPU-New Syllabus we.f academic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
(Scan Conversion)..Page no(2-16)
Computer Graphics (SPPU-Sem.4-1T)
Find out which would be turned
2.3.12 pixel on
Hene we points on a line (4, 4)to (12.9) Example
get fvllowing
with end (2, 2) to (6, 5) using the same,
for the line points

2.3.2.
Solutlon:Refer Section
4

Given:, 2.
y =2 ^ =6. =5 y2

Dx -,4 Dx =2 (3) -(4)


Dy= ya-y1
=3
G
2 2 Dy

3
G
Plot 1 point (2. 2) here as IDxl> IDy! that means line is

Gentle slope, so we have to move on x till xz i.e. 6.

11
After plotting 1" point as (2, 2) increase x by 1
12

G=2 Here
Exemple
2.3.11 Consider the line from (0.0) to (6,6)
We have to increase y by and update G as,

,
1
Brevenham's algorithm to rasterize this line.

Solution: Refer Section 2.3.2. G G+2 (Dy-Dx) =2 +2 (3 -4)= 0


Given:
A =0. y, X26.=0 =6 So, plot next point as (3, 3)then again increase x by
1
Dx= h. - =6-0 =6
x.l
Now it will become x = 4.

D 6 -0 =6
= h.- yl= Here G 0.

2Dy - Dx = 26)-6 12-6 =6 We have to y by 1 and update G


increase as,

Lets plot 1 point as (0. 0) G G+2 (Dy -Dx) =0+2(3-4) = -2


Since Dx =Dy the line is in So, plot next
gentle slope category. The point as (4, 4) then again increase x by 1.
line is
having siope as Now it will become x = 5.

Here G = -2.
It means we have to move along x direction from x, to
So, don't increase y just update G only as
X and find the
corresponding y value. G =G+2 Dy=-2+2(2) =2
After ploing 1°" as (0,0), increase So, plot
x by (5, 4) go on doing x reaches to
x. We
point 1. this till

x becomes 1
will
get points as,

G>0,so update y by 1 and modify G as


Here
G = G+2 (Dy- Dx)
=6+2(6-6)=2
Plot next point as (1, 1)

.
Now again increasing x by 1, x becomes 2,Here
G =6
G >0,so update y by

5
Since and modify
1
G as

Dx) =6+26-6) =6
G G+2(Dy -
Plot next point as (2,2)
Go on doing this till x becomes X2. Hence we s
get
following points on a line (0, 0) to (6,6) as
Example 2.3.13 Give Bresenham
line
for
the drawing algorithm
generating
points on line
points are segment, when two
ena

232
given as input. the line
Digitize with end-poins
P(20,20) and Q(10, 12)
using the same algorithm.
Solution:Now, let us calculate
of line the pixel co-ordinates
PQ.
4 Given
5 P(x. y) =(20,20)
66 Q)= (10, 12)

(SPPU-New Syllabus w.e.facademic year 20-21) (P4-28)


e Tech-Neo
Publications..A SACHIN SHAH nture
Ve
Computer Graphics (SPPU-Sem.4-HT) (ScanConversion)...Page no (2-17

X= Y1=20 to draw a line using Uni

2= 20; Example 2.3.14 Give the algorithm


whose end
12 DDA. Use this algorithm to rasterize the line

. D
10;
= X2-X1 =10-20 =- 10
Y2
points

Solution:
are (3, 2) and (10, 8). In Sem-

D,= Y2-yi =12-20 =- 8 Given: X -3, Y, =2 x = 10, Y, = 8


D, and are we
Since,
D, negative will take their
D X2-X =10-3 7
absolute values.
=8-2 =6
D, =10 and
D,= 8
D,
Since
y2-y
IDI> ID,I the line is of gentle slope category
Now, let's find decision factor G,
Steps= abs (D,) =7
G 2D,- D, = 2(8) -10 =06
G =6

so we
Here, since

value for
need to

each x
D, > D, the line
move along x axis
till x becomes equal
is

and
of gentle slope category

to
find

20.
corresponding y

As we know 1
Aincrement

Yincrement

point,
Stepps
let's
D
Steps

plot it as (3, 2)
0.85

First plot point (10, 12),


aew Xold +Xincrement3+1 =4
Now increase x by 1
new Yold tyincrement2+0.85 =2.85
.X =11 But here we need to round off 2.85 as 3 for displaying

Here, G =6 i.e. positive so increase y by 1 and update G that point

.
As, G G+2(D,-D,)
= 6-4 2 = 6+2(8- 10)
new
for next iteration

Xold+ Xincrement4+l
=5
Yoldt Yincrement2.85 +0.85 =3.7
Now x=
plot 11, y 13, new

Now, G =2 Like this we will calculate points till ynew becomes

equal to ie. 8
Again G is positive so again increase y by 1 and update y,
The table summarizes the
G as, following points.

G =G+2(D, -D,) =2+2(8-10) X Plot


= 2-4 =-2 3,2
Now x=
ploty
= 14 12,
2.85 4,3
Now
3.7
5,4
G=-2 Negative.
since i.e.

9
4.55 6,5
G by,
Next time don't
G
increase

G+ 2(D,) = -2+2(8) =-2+ 16 = 14


y and update
5.4 75
6.25 8,6
Now,plot x= 13, y =14) 7.1 9,7
Like this we will get following points. 10 7.95 10,8

Example2.3.15:Explain DDA line generation algorithm.


10 12 Rasterize the line segment with starting point as A(1, 0) and
end point as B(5, 7).
11 13
123 14 Solution:
14
Given:=1, y1 =0,=5,y2=7
15 D -z,=5-1 =4
16 D, Ya-Y1 =7-0=7
16 17 Since IDJ> D,I the line is of
17 18 steep slope category

18
20
19
18

19

20
increment Steps
D Steps
=057
abs(D,) =7

SPPU-New Syllabus we.f academic year 20-21) (P4-28) SHAH Venture


Tech-Neo Publications..A SACHIN
ComputerGraphics (SPPU-Sem.4-IT) (ScanConversion)...Page no (2-18

increment
=
Steps
=1 Plot next point as (6, 7)
Now again increasing
x by 1, x becomes 7,Here
G=0
Asweknow 1" point,let's plot it as (1,0) So update y by - 1 because y, > y2 and update G as,

Anew old Xncrement1 +0.57 =1.57 G G+ 2(D,-D,) =0+2(3-4) = -2


new Yoldt Yincrement 0+l= 1 Plot next point as (6, 7). Go on doing this
til
2 for displaying becomes X Hence we get following points on a line
But here we 1.57 as (5, 8)

x
need to round off

to(9,5)
.
that point

for next iteration

Xnew Xokd+ Xincrement 1.57 +0.57 =2.14 5


new Yokd increment 1+1=2 6
Like this we will calculate
points till
ynew becomes
7 7
equal to y i.e.7

The followingtable 8 6

XY|
10 10
summarizes the

Plot
points.

Example2.3.17: Consider the line from (,5) to (13,9).Use


2,1 1.57 the Bresenham's algorithm to rasterize the line.

3 2.14

2.71

3.28
2 2,2
3,3

3,4
Solution:
Given:X =5,
Dx = x2-X,l=
=13, y29
- =8
y=5
113 51

5 Dy= ly2-yl= 19-5l =4


3.85 4,5 2D,-D,=2(4)-8=8-8 =0
G
4.42 6 4,6
Let's plot 1"
4.99
7 5,7 Since
point as (5, 5)

IDI> D,I the line is


of Gentle slope category
Example 2.3.16 Explain Bresenham's line So we have to move x tillxz
in detail.
drawing along i.e. 13
algorithm Rasterise the following line
Bresenham's line
using
- After
1 point as (5, 5), increase x by

Solution:
generating algorithm P1(5, 8) P2(9, 5).
x plotting

becomes equal to 6
1.

.
Given:X =5,
D
y1

lxz-X,l= 19-51 =
=
D,=ly2-y,l -81= 3
4
=8 .X2=9,y2=5

I5
Here

G
G
So update y by
=0
1 and modify G as
G+2(D,-D,) =0+2(4-8)
G
2D,-D 2+2(-4)
2(3)-4=6-4
Let's plot 1"
2 2-8= -6
point as (5, 8). Since
IDJ> D,JI the line is Plotnextpoint as (6, 6)
of Gentle
slope category
Now again increasing
So we have to move
along x till xq i.e. 9
xby 1, x becomes7,Here G =-6
So do not
update G as,
After plotting update y and
1" point as
(5,8), increase x by G =G+2(D,) =-6+2(4)=
.x becomes equal to 6
1.

Plot next
-6+8 2
Here G>0 point as (7, 6). Go
So update y by - because y,>
1
becomes
to
xHence we get following
on doing this
points on a line
till

("
y2 and modify Gas (13,9).
G G+2 (D,-D,)=2+2
(3-4)
2+2(-1) =2-2 0
(SPPU-NewSyllabus w.e.f academic year 20-21) (P4-28
Computer Graphics (SPPU-Sem.4-IT)
(Scan Conversion)...Page no (2-19)
X
Y Unit
5
5 InSem.
6 5

9 Example2.3.19(SPPU-Q. 1(a), May 17,6Marks


Rasterize a line from (0,0) to (8, 4) using DDA
10 algorithm.
Solution:
11 8
9
GivenX =0, y, =0, X 8, y2=4
12
DX= (x2-X1) =(8-0)=8
139
Example2.3.18 (SPPU 0.2(a),Dec.17, Q.1(b),
DY = (y2- Y) =(4-0)
As IDXI> IDyl the line is
4
Dec. 18 gentle slopecategory
Marks) 6 steps = abs (DX)=8
Bresenham's algorithm
Interpret to
find which are pixel are
urned on for the line
segment between (1,2)and
Dx
(7,6).
Aincrement
steps
Solution:
Bresenham algorithm for
increment
steps
example
From the given information we can put first
Given:= 1.y, =2 7,y2=6 point i.e. (x1, Y)
Dx=X2-X, =6 new Kold +Xincrement 0+1 =1|
Dy y2-Y1 =4 Ynew Yold + Yincrement= 0+0.5 =0.5
G 2Dy -Dx =2(4) - (6) =2 But here we have to round off 0.5 as 1 for
displayinng
that i.e.
point per display is (1, 1).
Plot 1 point (1, 2) here as IDxl>
IDyl that means line is
Gentle slope, so here For next iteration
we
have to move on x till
x2 i.e. 7.
After ploting 1"

Here
X 2point as (1, 2)increase

G= 2
x by 1 Anew

Ynew

.
Xold

Yola
+ Xincrement

tYincrement0.5 +0.5 =1
Next point for
display
1+1=2

will be (2,1) Now loop


steps
are tabulated as follows.
We have y by 1 and update G as,
to increase

G G+2 (Dy -Dx) =


= 2+2(4-6)=-2 Display
So,plot next point as (2,3) then 0,0
again increase x by 1.
Now it will become x =3. 0.5 1,1
Here G = -2. 2 2,1
So, don't increase y just update G only as 1.5
3,2
G = G+ 2Dy =-2+2(4)=6 2 4, 2
So, plot (3, 3)go on doing this x reaches
till to x2. We 2.5 5,3
will get points as,
6 6,3

2 8 3.5

4 8,4
7,4

4
(SPPU-New Syllabus w.e.f academic
3

year 20-21)(P4-28)
Example
algorithm
the lien with
2.3.20
and

Tech-Nea
find

end points
Write and
out which

(3,
explain Bresenham's line
pixel would be turned on for

2)to

Publications..A
(7,4)using the same.

SACHIN SHAH Venture


(ScanConversion)..Page no (2-20)
(SPPU-Sem.4-IT)
Computer Graphics +lz-l|
new old tXincrement-2
Solution: +0.5 =-0.5
Ynew Yold +yincrement-1
Given: X = 3,y,=2
we have to round off 0.5 as
- -1 for displaying
But here
X2 7, y2 =4 is (-1,-1).
that point i.e. per display

Dx= -X1=4 For next iteration

Y2-Y1 =2
Dy
G 2 Dy - Dx =2 (2)-(4) =0
Anew Aold + Kincrement

=
-1+1=0
-0.5 +0.5 =0
Ynew Yoid Yincrement
means line is
Plot (3, 2) here as IDxl> IDyl that
be Now
1
Gentle slope, so here
point
we have to move on x till x2 i..e. 7. Next point
for display will (0, 0) loop steps

. are tabulated as follows.


After ploting
1" point as (3, 2) increase x by 1

X 4 YDisplay
Here G=0
We have to increase y by 1 and update G as,
-2-1 2,-1

G =G+2(Dy- Dx) =0+2(2-4)z-4 -1-0.5 -1,-1

So, plot next as (4, 3) then increase x by 1. 0 0,0


point again
Now it will become x = 5.
0.5 1,1
Here G-4.
So, don't increase y just update G only as
2 1 2,1
G =G+2Dy =-4+ 2 (2) =0
3 1.5 3,2

will
So, plot

get points
(5,

as,
3) goon doing this till x reaches to
xg. We
4224,2 2.5 5,3

2 3 6,33

3 Example 2.3.22 Consider a line from (2, 5) to (8, 8). Use


Bresenham's line drawing algorithm rasterize this line.
5
Solution:
6
Given X1 2, Y=5
X=8,
Dx = X2-X =6
y2=8
Example 2.3.21
Explain DDA line drawing
- algorithm.

.
Consider line segment from A(-2,
to B(6,3) use DDA
line
drawing algorithm to rasterize
1)

this line.
Dy=Ya-Y=3
G 2 Dy -Dx =2 (3)-(6) G=0
Solution:
x =-2, Y,=-1, ^=6, 1
Plot
Given point (2, 5) here as I Dx 1>1 Dy Ithat means
y2=3
DX= (2-x,)=(6-(-2))=8 line is Gentle slope, so we have to move on x till xz i.e. 8.

DY=Y-Y)=(3-(-1)) =4 After ploting 1" point as (2,5) increase x by 1

As IDXI> Dyl the line is gentle


x =3
slopecategory
Here G>=0
steps= abs (DX)=8
We have to increase y by 1 and
update G as,
Aincrement steps G G+2 (Dy -Dx)= 0+2(3-6)=
-6
. :" So, plot next
iacrement
steps 0.5 Now it will
point as (3,6) then
again increase x by
become x =3.
From the given

( Y)
information wecan put first point i.e. Here G6.
(SPPU-NewSyllabus w.ef academic year 20-21)(P4-28)
Tech-Neo Publications
sA SACHIN SHAH Venu
Computer Graphics (SPPU-Sem.4-IT) Conversion)...Pageno (2-21)
(Scan
So, don't increase G only as
y just update Unit
= G+2 Dy =- +2 (3) 0
=
G
x
6
X,Y
6) go on x reaches
x. We
this
So, plot (4. doingg till to
In Sem.
will as,
get points

3 6

Fig. 2.4.1

6 We could use this to calculate the position of


equation
on circumference
points of circle
by stepping along x
axis from (x - 1) to
(x + r) and calculating the

correspondingy-values at each position by using,

2.3.3 Comparison of DDA and y y.tV?--x


Bresenham's Line Drawing We derived this equation from the equation of circle

only.
Algorithm
i.e. (y-
y =r-(%-x
Sr. DDA Bresenham
No.
Based on increment
1. Based on increment y y.t Vr-a-xJ
method. method. But this is not best method for generating circle as one
2. Use floating point Use only integers. of the problem with this method is that it leaves uneven
arithmetic.
spaces and needs more computations at each step.
3.
Slowerthan Bresenham Faster than DDA See Fig. 2.4.2. We can minimize this problem of
4. Use of multiplication Use of only Addition spacing by interchanging the position of x and y.
and division operations. and Subtraction
But there is another way to solve this spacing problem.
operations.
And that is by using polar co-ordinates r and 0. We use
5. To display pixel we need No need of floor or
parametricpolarform to yield the pair of equation as,
to use either floor or ceil ceil function for
function.
display.
x
X+rcos y=ye+r sin
6
6. Because of floor and ceil No error component
function error is introduced.

component is

introduced.

7. The co-ordinate location The co-ordinate


is sameas that of location is sameas
Bresenham. that of DDA. Fig. 2.4.2

With this we are displaying points at fixed


angular step

Syllabus Topic: Circle DrawingAlgorithm size. The step size chosen for 6 will depend on

application. See Fig. 2.4.3.

2.4CIRCLE GENERATING ALGORITHMS We can reduce the computations by considering the

symmetry of circles. By using this symmetry property


A circle is a set of points that are placed at a given there is no need to find each and
every point on the
distance 'r from centre (x» Y). See Fig. 2.4.1. This
boundary of the circle.

distance relationship
is expressed by Pythagorean
Theorem as,

(-+yy =
(SPPU-New Sylabus w.ef academic year 20-21) (PA-28) LTech-Neo Publications.A SACHIN SHAH Venture
Computer Graphics (SPPU-Sem.4-1T (ScanConversion)..Page no (2-22)

2.4.1 Midpolnt Circle GenerationAlgorithm


(e+reine)

.
(x.y)
GQ.Explain Midpoint circle generating algorithm?
******* ******* *******^.* * *o-~--..
Here we have to determine the closest pixel position to

the specified circle's path at each step. For this we have


and
(rooe) to accept radius
'r
center point x and
y, See
Fig. 2.4.5. We will first see for center point as
origin
Fg. 2.4.3 (0, 0). Then each calculated point is to be moved to

We can divide the circe in 4 quadrants or in 8 octants proper position by adding X, and Y. to
corresponding
also. Here we will find only one octant's co-ordinates x and y-value.
In first quadrant we are moving in x-

and then we will just replicate hat one octant's co- direction with starting point as x =0 to ending point

ordinates to rest seven octants. See Fig. 2.4.4. x =y.


Suppose we have calculated a point (x, y) then from To apply a midpoint method, we define a circle

this (x. y) we will plot rest seven points as (x, y). (y. x), function.

(-x.y).-y. x). (x, - y). (y.


- x), (-x,- y). (-y,-x).
So using this symmetry proper circle generation

becomes fast.

(x.y)

(0,0)

Fig. 2.4.5

farck (,y)=x+y-f which is sameas r=x+


Fig. 2.4.4
Which is
derived from equation of circle,

With Cartesian equation of Pythagorean we have to (x-x+y-y =r.Buthere we are considering


perform muliplication and square root operations, Ye as (0, 0)

while in

multiplications
parametric equation
and trigonometric
we have
calculations.
to perform
+y =?.
Any point (x, y) on the boundary of the circle with
Both these methods require more computational time. radius r satisfies the equation feicle (x, y)
0. If point is =
So we have another method of Bresenham's which inside the circle, then circle function is and if
negative
totally deals with integers and performs only addition
then
point is outside circle circle function is positive.

and so is fast also. This method is


subtraction, it
i.e. if
feick (a, y)<0, then x, y is
inside the circle
applicable for different types of curves also.
boundary
There is one more approach which is called as midpoint
0, then x, y is on circle boundary
circle generation. This approach generates the same
So 0, then x, y is outside the circle boundary.
pixel positions as the Bresenham's circle algorithm.
Thus the decision parameter in this
first we will see midpoint circle
generation algorithm.
circle function is

Circle Generating algorithm. Assuming that we have just plotted X Y


Now we have to determine whether next

E
Algorithmns point. pont
&+1,y) is
closer or (K+1, y-1) is closerto actual
Midpoint Circle GenerationAlgorithm
circle. See Fig. 2.4.6.

2. Bresenham Circle Generation

Fig. C2.2: Circle Generating Algorithms

fmtre
Computer Graphics (SPPU-Sem.4-1T)
k+1 Xk+2 (Scan Conversion)..Page no(2-23)
Unit

k EI
Yk-1- In Sem.

Y-2

Fig. 2.4.7

Our decision parameter (P)is


Fig.2.4.6

circle function.
--
or P
Therefore
fcince +
we will
1,Y-1)
take midpoint of these two points as,
Ifradius r

2.4.1(a) Steps for Midpoint


is integer we will round it as Po= 1-r.

Clrcde Generation

P face+1,%-12) Algorichmn

= %+1)*+ (-1/2)- from circle


equation GQ.What are the steps for Midpoint circle generation
If P <0, then it means this point (x, + 1, -1/2) is algorithm?
inside the circle. So we have to plot pixel (x,+ 1, y 1.
Accept radius 'r' and center of circle (x.y) from user
After this we have to increase x by and
1 point on circumference of circle.
1.
plot

ie.
Paewfarie(My+ 2, Y-1/2) o Yo)= (0, r)

if
+2
we solve this
+U-1/2)-
we will
2. Calculate the initial value of the decision

1-r
parameter.

get Po
P new P+(2 x+1) 3. If we are using octant symmetry property to plot the

ie. when, earlier we have not changed row. pixels, then until (x < y) we have to perform following
steps.
we select y-1 for displaying.
IfP,>0thenthen will Like 0
this we will select the point to be
displayed.
If P is less than

modify P, as P, = P+2x + 1 and


Pawfircie (kgt+ 2. Y-3/2)
then increase x by 1
+2)+-3/2)-
otherwise
After solving above equation
we will get,

Punew P+(2x-2y, +1) modify Pas P =P +2(x-y)+ 1 and

increase x by 1
i.e. when, earlier we have changed row.
and decrease y by 1

Similarly the initial decision parameter is obtained by


the circle function at start position
Determine the symmetry points in other octants also
evaluating

g:Yo)= (0, r). See Fig. 2.4.7. 3. Since we have derived all formulas by considering

Now calculate the decision parameter.


center point as origin. Move each calculated pixel

position (x. y) on to the circular path centered on


Po fsirce (%+ .y- 1/2)1

(x Y) and plot the co-ordinate values as


But X =0 and
= x+X
x and y=y+Ye
+1=1
Po
--
-1-az-i1+-
and Y-1/2-r-2

t-(-)-
have

plot
But
to add
the point.
actually

that
the center

center
point

co-ordinates
may
to
be anything,

midpoint x and
so we
y to

(SPPU-New Syllabus wefacademic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
(Scan
Computer Graphics (SPPU-Sem.4-1T)
Conversion)...Page no(
float dps
Program 2.4.1: MidpointCircle generation program ilinitialising the
parameter.
descisic

Program
xl=0; Ilinitialisng the
X,Y
cordinates.
AC program to draw a
circle by using midpoint cirele
yl rad;
generation algorithm
dp 1 rad;

#incudeiostream.h> while(xl<yl)

includeconio.h>
#includestdlib.h> if(dp=0)

#include<graphics.h>
inchudedos.h> xl++
void cire_midpt(intx.int
y,int dp + (2"x)+1;
.
rad);

void
display(intint,int,int);

=**=** .. .

.
=*
zsss**5 else

Function Name :Main


Purpose : To initialize
graphics mode and call
mid point circle
yl
======*=s:
function dp+2*(xl-yl)+
=* .: .

voidmain display(xl,yi,x,y); ;
int gd =DETECT, gm, x,y.r;

initgraph(&gd,&gm,'c:\ltepluslbgi):
cleardevice0:
cout"Midpoint circle
generation algorithm"; Function
"n enter the center
Name display
cout
cin>>x>>y;
co-ordinatesfor the circle
Purpose To plot the pixels on circle by
symmetry
cout"n enter the radius of the
circle";
property.

cin>>r;
cire_midpt(x.y.r); void display (int
xl,int yl,int x,int y)
getch0:

closegraph0:
putpixel(xl+x,yl+y,WHITE);

/plotting the pixelsby using symmetry,

== putpixel(xl +x.y-yl,WHITE);

Function Name
putpixel(x-xl.yl +y,WHITE);
cire midpt
putpixel x-xl,y-yl,WHITE);
Purpose To drawa circle by mid
putpixel(x+yl,y+xl,WHITE);
point circle generationalgorithm
putpixel(x+yl.y-xl,WHITE);

putpixel(x-yl,y+xl,WHITE);

void cire midpt(int putpixel(x-yl,y-xl,WHITE);


xint y.int rad

int yi
Computer Graphics (SPPU-Sem.4-1T)
(Scan Conversion)...Page no (2-25)
Output 2.4.2 Bresenham Cirde
Generatlon Unit

Se
circle generation algorithm
Midpoint
This does only
co-ordinates for the algorithm which
enter the center circle integer arithmetic
makes it faster than
320 floating point. We are creating only
one octant of the circle i.e.
from 90° to 45°.
240
See Fig. 2.4.8. We derive other seven octants
enter the radius of the circle of the
circle by symmetry property. The circle is
150 generatedby
considering center point as with radius 'r.The
origin
algorithm calculates one new From any
pixel per step.
point(xq on the circle, the next
y,)
point (x, + 1, y,+ 1)
must be
Example 2.4.1 Plot
a circle whose radius is 3 and whose either one on right or one to the right and
center co-ordinates are (0, 0). down.

Solution: Given :r=3,x.=0,y.=0


Plot 1 point as (0, r) ie. y = r

Plot (0, 3)
Like that find out other points from (0, 3) by using
symmetry property

So plot (3, 0)

plot (0,-3) Fig. 2.4.8

plot-3, 0) If is a current with


P, co-ordinate
y)
= 1-r point (x» then

P
find P

1 -3 = -2
from Fig.

could be either
2.4.9

A
we
or B.
will come to know that next point

Till
(x<y)we have to
perform following
Point A will be having co-ordinates (x,+ 1, y,) and I

If(P<0) will be (xa+ 1, ya- 1) so for selecting one of these two


In this case P =-2 candidatepixels we have to perform sometest.
So we have to increase x by 1 and P as To do this, we know that a function of a circle is
modify fsircle

P P+2x +1 x.
y)=x+y-
ie. P = -2+2(0) + =-2+1=-1 1 This function determines a circle with radius 'r' around
Here we are not increasing y. the origin in the following way:

Plot (x+ 1, y) ie. (1, 3) If f y) = 0


x, then (x, y) point is on circle. If

f (x, y) < 0 then (x, y) point lie inside the


Again continuing process we will get following
this circle

table.Then plot the co-ordinates Iff(x, y) > 0 then (x, y) point lie outside the circle. i.e.
of this table by using
symmetry property as shownin Fig. P. 2.4.1.
for point A the equation of circle will be

f(A) =f(%,+ 1. y,) =(%,+ 1)+y, -r

Yn-
Yn-1-

2 Fig.2.4.9

and for point B


Fig.P. 2.4.1 fB) f(a,+ 1,y.-1) = (a,+1+0.-1)'-r

(SPPU-New Syllabus w.e.f academic year 20-21) (P428) Tech-Neo Publications..A SACHIN SHAH Venture
(ScanConversion)..Page no (2-26)
Computer Graphics(SPPU-Sem.4-1T)

=0 we have (B). Here we are going to plot a point A because


Now if f (A) then point A lies on circle so it io
is
more near curve than the point B.
to plot that point else we have to check, if (f(A)<0)
to actual

ie. Is point A lies inside the circle. Or if (f (A) > 0), i.e.
Similarly in case 5, the curve is below to both points A
ls
point A lies outside the circle and accordingly we and B i.e. both points are outside means the f (A) and e
(B) must be > 0. Here also we are selecting
have to select a
particular point. a
point
To select one point fom A and B we are having which more nearer to the curve. In
five is this case point B
different cases, Fig. 2.4.10 shows sketches of all the is more nearer so we are selecting that point.
five cases with two
candidatepixels A and B. Now to decide when to select point A or point B,
A we
are using sum variable. Here we are interested in onlv
Case
B the sign of sum variable.
Above A Case 2 Case 3
A
Through Between
A &B In case 1 both f (A) and f (B) are negative so the
sum
A will be obviously negative and in case 5 both f (A)and
B
f B) are positive so the sum will be positive only.
From this we can make a statement as, if the sign of
Case
Case 5
Through B sum variable
Below B is
negative then select point A and if the
Fig. 2.4.100 sign of sum variable is
positive then select point B.
To determine which In case 3 of Fig. 2.4.10
point to select we are using point A lies outside the curve
equation of To be more
circle.
specific, we are dealing andB lies inside. So f (A)
mustbe>0and f B) must
with only the be <0.
sign of that function,if it is
positive. negative or
Then the sum
Let us summarize this
variable will contain either
negative or 0
a tabular form or positive
result in
for all the value, depending on the value
5 cases. of f (A) and
f(B). Ifthe sum is
negative or 0, then pixel A is closer
to circle and we
Case 1 2 have to select A point. If it is
then, we have to select positive
point B.
f(A) 0 We are going to choose the
point A or B depending on

0,+
f(B) sign of sum variable. It is not
both formulas and necessary to calculate
Sum the sum for every
step.
The starting
pixel Po is taken as,
Observe the case 2of Fig. 2.4.10. Here curve
passing
is a Yo)= (0, ).
through point A f (A) must be
i.e. Refer Fig. 2.4.11.

point B is equal to 0; And as


lying inside, f (B) < 0.So we are
Then f(A) = f(x+ 1, yo)
point A. selecting

(+1+(Y-?
Similarly observe case 4 of Fig. 2.4.10. Here B is
lying on curve and
point A is lying outside.
point
o Yo)
(0+1+()-f=1
So, f (A)
must be > 0 and f (B) must be equal to 0.
These two cases are the
simplest cases. But if the r-1
situation is like case 1 or case 5. Then in
both cases the
curve lies on one side of both r-2-
points.
Let's concentrate on case
1. Here curve is
B point. It means both points A and B above A and 0,0
are lying inside
the curve then both
f(A)and f (B)mustbe <0.
Fig. 2.4.11
So which point to select? Since both
points are inside
Similarly, f(B) =f(x+1,yo- 1) =f
only, we are introducing new term (7+1,r-1)
"sum"which will be
f(B) (0+ = 1
summationof both f (A)and f(B) ie. sum f

(SPPU-New Syllabus w.e.facademic


(A) +f

year 20-21) (P4-28)


=
. Sum
=
0+0+1+r-2r+ 1-f=2-2
f(A)+f(B)
+(r-12-

=1+2-2r
I
Computer Graphics(SPPU-Sem.4-1IT)
(Scan Conversion)...Page no (2-27)
Sum = 3-2r
Unit
Sodepending on whether sum is <,> or 0, we will = Yn-
select A or B as next point. And we can find next
sum Pa
Yn- 1- In Sem.
going from P,
to P, by considering old sum (S) value.

2.4.12.
Yn-2-
Consider Fig.
xnX+1 h+2
If we want to make it
generalized then
Fig. 2.4.14

Snew (x,+2)+(y,-1)-r
Yn-1 +
+(M, 2)+(Y, -2-?
Yn-2 Solving this we will get,

Fig. 2.4.12 This shows that


.
Snew-S

calculating
4(%,-ya)+10
Sew= S+4 (x,-Yn) +10p
Snew from old 'S' is very
Sum=f(A) +f(B) =f(%,+ 1, y,) +f%,+ 1, Y,- 1) simple. It uses very few operations like addition, subtraction

S=+1+y, -f+(«,+1 +V,-1'-F


and
this
multiplication.

'S' variable to
Here, we are making use of just
determine which draw.
sign of

Step1 If S <0 then we will print next point as A pixel to

i.e. (,+ 1, y,). We will call this


point as (P+ 1). 2.4.2(a) Steps for Bresenham's Circlee
Now in order to go for next pixel i.e. (P, + 2) we Generation Algorichm
must compute sum again. We will call this as Sew
and express it using point P,. SeeFig. 2.4.13.
GQ. What are the steps for Midpoint dircle generation
1
Pn Pn+ algorithm?
n
UQ What.are the steps of Bresenham's cirde algorithm ?
Yn Explainwith example.

Yn- (SPPU-Q.2(a), May 17,0.1(a), Dec.17


Q.1(a), May 18, 6Marks)

n+n 1. radius and center from user and


Accept co-ordinates

plot first point on circumferenceof circle.


Fig. 2.4.13

= f(A)+ x,y)= (0, r)

S = f%,+2, y,)
f (B)
2. Calculate the initial value of decision parameter.
+f(x,+2.y,- 1) S = 3-2r
S
'Snew =(,+2 +y,-r+G,+2+(ya-1)*-r 3. If we are using octant symmetry to the

'
property plot

Solving this we will get, pixels then until (x < y) we have to perform following

4x,+6
Saew-S

S=
steps

Snew S+4x, +6 If 0)
For the next pixel point A
S by S =S+4x +6 and increase xby 1.
(P +2)we have to select Update
if
Saeu 0 else select point B. else Update S by S =S+4 (x -y)+ 10o

Step 2: But if at initial stage, S>0 then we will print and increase x by 1 and decrease y by 1.

P+1) as &,+ 1, ya-1). 4. Detemine the symmetry points in other octants also.

See Fig. Move each


2.4.14. 5. calculated
pixel position (x, y) on to the
Now in this case to find P,+2 circular
path centered on (x Y) and plot the co-
ordinate values as,
SneWf(A) +f(B)
= fx, +2,y, -1)+f(x,+2,y,-2) x =X+X and y =y+Ye
(SPPU-New Syllabus w.e.f academic year 20-21)(P4-28) LTech-Neo Publications.A SACHIN SHAH Venture
Computer Graphics (SPPU-Sem.4.IT) (Scan Conversion)..Page no (2-28)

Program 2.4.2
Bresenham's Circle Generatlon
program
if(dp<=0)

dp + (4* xl) + 6;
Program:
else
AC program to draw a circle by using Bresenham's circle
generation algorithm
dp + 4(xl-yl)+10;

#include<iostream.h>
y
#includeconio.h>
xl++
#include <stdlib.h>
display(x1,ylay}s
#include<graphics.h>

.
#include dos.h>

void cire_bre(int x,int y,int


rad);
woid
display(int,int,int,int) Function Name display
Purpose To plot the pixelson circle by
void main0
symmeiryproperty

int
gd =DETECT, gm, x,y.r;

void display(intx1,int
initgraph(&gd,&«gm,'c:\teplusltbgi");, yl,int x,int y)
cleardevice0;

cout<"Bresenhamscircle
generation algorithm putpixel(l+x.yl+y,WHITE); /plotting the pixels.
cout< <n
enter the center
co-ordinates forcircle putpixel(xl+x,y-y1,WHITE);
cin>>x>>y; putpixel x-xl,yl+y.WHITE);
cout<"n enter the radius of
the circle putpixel(x-xl,y-y1,WHITE);
cin>>r;
putpixel(x+yl,y+xl,WHITE);
circ_bre(x-y,T); putpixel(x+ yl,y-xl,WHITE);
getch0;
putpixel(x-yl,y+xl,WHITE);
closegraph0
: :
putpixel(x-yl,y-xl,WHITE;

Output

Function Name circ_midpt


Bresenhams circle generationalgorithm

:Todraw a Enter the center

..
circle
co-ordinates for eircle,
Purpose by mid pointcircle
320
generationalgorithm
240
=*
void cire bre(int x,int

float dps

intxl,yl
.
xl=0; initialisng
ylrad;
dp3-2*rad;
whilexly
y,int

/initialising
rad)

the
descision parameter,

the X,Y cordinates.

:
enter the radiusof the circle

150

Example 2.4.2 (SPPU -0.2(a),May 17,Q.1(a), Dec.17


Q.1(a), May 18, 6 Marks
Plot a circle by Bresenham's algorithm whose
and center co-ordinates are (0,0).
Solution:
Given: r =3, x=0,
Plot 1 point as (0, r)
y.

i.e.
=0
(0, 3)
radius is
. .

a
**
Computer Graphics (SPPU-Sem.4-1T (ScanConversion)...Page no(2-29)
here

property

Then
0
x = and y

Find out
and
= =3

plot (0,

find initial
r

rest three

-
points

3),.

value of
(-3,0),
from

decision
this

(3, 0).
by using symmetry

parameter.
I
Unit

In Sem.

= 3-2r
S S

As S is
= 3-2 (3)=-3
negative
i.e. S <0. Fig.2.5.1

= X+ B. Unequalbrlghtness
x i.e. x
=(0+1)= 1
1
3and In this case a slanted line
appears dimmer thana
= S+ 4x +6 =-3+4(0)+ 6 = +3 horizontal or vertical
S line, although all are presented at the

same intensity level. The reason for this is the


Now new x and y i.e. plot (1, 3) similarly problem
plot continue
pixels on the horizontal line are placed one unit apart where
this process
til (x < y) then we will get following table. as those on diagonal line are approximately 1.414 units
Then after plotting these points we will get the circle as
apart. This difference in distance
shown in Fig. P. 2.4.2. produces the difference in

brightness. Refer Fig. 2.5.2.


This pixel positions are similar to the pixel positions

indicated cirele
by midpoint generation algorithm.

o o o
o o o
0 3
3

2 Fig. 2.5.2

2 C. Picket fenceproblem
1
Picket fence problem occurs when an object is not
Fig.P. 2.4.2 aligned with the pixel grid properly. See Fig. 2.5.3.

Here the distance between two adjacent pickets is not a


2.5 ALIASING AND ANTI-ALIASING multiple of unit distance between pixels.

2.5.1 Aliasing
The various forms of distortion that results from the
Scan

aliasing.
conversion operations are collectively called as
TTTT
A. Fig.2.5.3
Staircase
When we scan convert it into image it will result in
A common example of aliasing effects is the staircase uneven distance between since the end point of
pickets;
or jagged
appearance. see this effect We when scan
picket must be matched with pixel co-ordinates.

converting a primitive such as line or circle.


See This
Fig. 2.5.4. is sometimes called global
We also see the stair steps or jaggies along the border aliasing, as the overal length of the
picket is
approximately
of filled correct.
region.

Specifically when the resolution of the display is poor


or low and if the display allows only two pixel
states

ON or OFF in that case this effect can be noticed very

clearly. See Fig. 2.5.1.

Fig. 2.5.4

(SPPU-New Sylabus w.e.f academic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
Computer Graphics (SPPU-Sem.4-1T) (Scan Conversion).Page no(2-30)
And to maintain the proper/equal length spacing object in the scene i.e. It
computes pixel colors

sometimes it will distort the overall length


of fence. This is depending on an objects coverage.
sometimes called as local aliasing. See Fig. 2.5.5. It means how much or fraction of that
part pixel is

Additional covered by the object and depending on that, it sets the


plxel value of that pixel.

It
requires large number of calculations and
approximations. Prefiltering generates more accurate

antialiasing effect. But due to its high complexity of


Fig. 2.5.5
calculations it is not used.

2.5.2 Antialiasing 2.
******* Supersampling

:GQ What is the use of antialiasing


************** techniques? Supersampling tries to reduce the aliasing effect
by
Most occurs sampling or taking more than one sample per pixel. It
aliasing effects, in static images at a
moderate resolution, are often tolerable or
subdivides each pixel into 9 sub pixels of equal size
negligible.
But when the image which is often called as sampling
is moving or in animation this points
drawback becomes bold. See Fig. 2.5.6. Some of these 9 sub pixels may get
We can come out of this drawback by
color of background i.e. a line may not pass
straight way through
increasing the image resolution. But for that we have them and rest of sub pixels may get color of object.
to
extra
pay money and still the results are not always 3 samples
Suppose or sub pixels
There are 1/9 1/9 1/9
satisfactorily.
techniques that can greatly get background and 6 getscolor
reduce this effect and improve the images. Such foreground color then the color of the
techniques are known as 1/9 1/9 1/9
collectively
antialiasing. pixel will be the sum of
When we have displays that allow more
than two
colors, we can use the
the jaggies.
following techniques to soften 1/91/9 1/9 1/9
background
color. So
color and
of object

Fig.2.5.6 the value

a ultimately pixel
becomes the of
average several
2.5.2(A) Antialiasing Methods samples.

GQWhat are the different antialiasing methods?


3. Postfiltering
-***-**------

Antlallasing Methods 1/8 Postfiltering and


1/8 1/8 supersampling
are almost same. If we consider
1.
Prefiltering sampling points as in
1/8 50%| 1/8
supersampling, we may give a lot
2.
Supersampling more weightage to
1/8 1/8 1/8
center point. We
3.
could give the center as
Postfiltering sample
weightage of 50% or 1/2; and
Fig. 2.5.7
4. Pixel phasing 50% is distributed among
remaining
the rest of 8 samples. See
5.Gray level
Fig. 2.5.7.

So we can

1
treat
supersampling as the special case of
Fig. C2.3: Antialiasing postfiltering in which each
Methods sampling point has an equal

Prefiltering
weightage
G
This is a technique that determines pixel based Pixel
intensity phasing
on the amount of that particular pixels coverage by the
Pixel phasing is a hardware based anti-aliasing

technique.

SPPU-New Syllabus w.e.facademic year 20-21) (P4-28) Tech-Neo Publications...A SACHIN SHAH Ventue
Computer Graphics (SPPU-Sem.4-T) (Scan Conversion)...Page no(2-31)
The system in this case is
graphics capable of shifting In this case the screen is considered as 1 unit wide andU
individual pixels
from their normal positions in the I unit high.

by a fraction
The lower In Sem.
pixel grid
(typicallyor of unit left corner is origin (0, 0) and upper right

corner is The will be the center


distance between pixels. By moving pixels closer to the (1, 1). point (0.5, 0.5)
of the screen of the actual
true line. this technique reduces the aliasing effect. irrespective physical

dimensions or resolution of the display device.


5. Gray level See Fig. 2.6.1.

(1,0) (1,1)

can be as
displayed

Height
Fig. 2.5.8

Many displays allow only two pixel states, ON and


(0,0)
OFF. In that case we observe stair step aliasing effect. (Widthstar,
Width (0,1)

heightstart)
To reduce this effect we can make use of
gray level
technique. Fig. 2.6.2
In this technique allow The
display setting pixels to gray interpreter converts the normalize device co
levels between black and white to reduce the ordinates to
aliasing actual display device co-ordinates by using8
effect. Se Fig. 2.5.8. It uses the gray levels to some formula. Interpreter is a
program which converts
tum off the pixels in one row as
gradually it
gradually the instruction set or commandsto actual
image.
turns on the pixels in the next.
Assume that for actual
display the left most is
pixel

2.6 NORMALIZED DEVICE CO widthstart and there are width number of pixels in

horizontal direction is bottom most


ORDINATES Heightstart pixel
and height number of in vertical
pixels direction.

In normalized co-ordinates
GQ. What is a Normalized
Device Coordinates?
the screen is 1 unit wide but

*-*~*-w*-~.-*di******** in actual co-ordinates it is width units wide. So the


There are different devices having
display different normalized x should be
position multiplied by width
screen sizes measured in
pixels which is called as units to
get actual screen units. Refer Fig. 2.6.2.
resolution x x So
like (640 480), (640 320) etc. the When normalized co-ordinate x =0 at that time screen
program
not
displaying an image on one
display device
pixel will be x, = widthstart.
may display the same image on other display
device at sameposition or with same dimension.
screen width * Xnomalt+widthstart

Yscreen
= height * ynormal+
So, if we wish our program to be device heightstart
independent.
We should specify the co-ordinates in some units other
This will convert the normalized
co-ordinates into
actual screen co-ordinates.
than pixels and then we have to use the interpreter to

convert these co-ordinates to the Similarly we can derive a formula to


approximate pixel convert actual
values for the particular which we are using. screen values to NDC.
display
(1,0) (1,1)
AscreenW1dthstart
normal
width

normal
Yenheightstart
0.5,0.6 height

Example 2.6.1: Suppose resolution is 640 x 480 and we


have to convert
(0,0) (0,1) point (64,48) into NDC.
Solution:
Fig. 2.6.1
In this case, as
Let's convert
apoint (64,48)to NDC first.
The resolution is 640 x
device-independent units are called as Normalized 480, width is 640 and
device co-ordinates. height is 480. The widthstart and
(NDC) heightstart are set to
Refer zero
Fig. P. 2.6.1.

(SPPU-New Syllabus w.e.f academic year 20-21) (P4-28)


LTech-Neo Publications...A SACHIN SHAH Venture
ComputerGraphics
(SPPU-Sem.4-1T)
(Scan
Then. Conversion)Page
no(2-32
So, if we use

'
square area
larger than
i.e. 640x 640 instead actual
of 640x 480, then displav
we mav
48010 full screen and have
image also
properly
ay use

(p Yn = (0.1,0.1) but the image


may not
entirely fit on the
proportionate

Now let's
that we have to take care that our
display. Sofo
or
convert this image size
(x y,) back to
(x,, y,) should no
get increased to our actual size of
display device.

x,6-40x+0 64 2.7 CHARACTER GENERATION

But
y,= 480 x+048 GQ. Explain Bit-Map character
there will be small We mentioned generation method.
NDC problem.
is 1 unit wide and 1 unit
that
GQ. Explain
characterGeneration methods.
our actual
display devices are
high i.e.
square. Generally ********* ****
rectangular i.e. 640x 480.
Usually characters are
In such case we will not get the generated by hardware. But we
scale.
image according to can
generate/prepare characters by software also.
There
are three
For this we can primary methods for character
use displays full
either generation.
height and width First is called as stroke method or vector
ie. 640 x 480 in
conversion formula or use character
numbers generation and the second is called
which coresponds as dot-matrix or
square area of display device i.e. bitmap method and third is called as starbust
instead of 640x 480 we will method
consider only 480 x 480.
(0,0) Character Generation Methods

48
1. Stroke
Actual x=64 method/vector character

Helight 48 screen
Ys48 generation method

Dot-matrix or bit-map method


Width 640 www.cr

3. Starbust method

(0,1) (1,1) Fig.C2.4: Character


Generation

(1) Stroke method/vector character


1/10
n method
generation
NDC 1/10
(0.1,0.1) Yn
This method creates characters by using a set of line
(0,0) (1,0) segments.
We could our
build own stroke method by vector

(0,0) generation algorithm or by using any line


generation
method.
48
Aotual X64 To produce a we o
character will give a sequence
Helght 480
8oreen
y48 commands that defines the start
point and end points of
the straight lines.

Wldth 640
(By using this we can change the scale of the characters
Fig. P. 2.6.1 We can make a character twice as large as its original

But we use full size Similarly we can get characters slanted


if area then our image will get stretched also.
using this method we can change the
or squashed. style of charactes
also. Different character
styles are shown in Fig2.7.
If we use square area, will be

A
image properly

AA
proportional but we are wasting the area.
display

Fig. 2.7.1

(SPPU-Newsyllabusw.ef academic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN


nture
SHAHVenu
Computer Graphics (SPPU-Sem.4-IT)
(Scan Conversion)...Page no (2-33)
(2) Dot-matrix or bít-map method
Bitmap fonts
require more space, because each Unu
In this scheme. characters are variation or format) must be stored.
represented by an array
(size,
of dots. The size of this
array may vary. An array of5 I Sem.
dots wide and 7 dots high is
(3) Starbust method
generally used. but 7x9
and 9x 13/14 are also used. We can sclect In this method a fix
any size of pattern of line
segments are used to
aray generate characters. There 24 line
are
segments and out
of these 24 line segments,segments to
required display
for particular character are highlighted.

This method of character


generation is called Starbust
Hegh4
Helght 5|
method because of its
characteristic
appearance.
The pattern for particular character is stored in the form
of 24 bit code. Each bit
representing one line
segment.
The bit is set to one to
highlight the line
segment.
Otherwise it is set to zero.

Wdth

Fig. 2.7.2 3
This array is like a small buffer, justbig enough to hold
a single character.
21
The dots are the 20
pixels of the

Placing

matter
the character

of copying
on the

pixel values
small

screen
array.

then

from small
becomes
character
a V10 10
Starbust pattern of
Starbust pattern for
array into some portion of the screens frame 24 line
segments
buffer. See character E

Fig. 2.7.2.
Fig.2.7.3

7 A bitmap
define each
font uses a
character.
rectangular pattern of pixels to

The entire font can be loaded an


into area of memory
called font cache displaying character means then

copying characters
image from font cache into the
frame buffer at the desired position.

24 bit code for character E is,


Bit number

But its
oo0|ooo
main disadvantage is, it requires more memory and requires additional
oo1 code conversion
programs to display
Characters from the 24 bit code.

SPPU-New sylabus w.af academic year 20-21) (P4-28) LTech-Neo Publications...A SACHIN SHAH Venture
(Scan
Computer Graphics (SPPU-Sem.4-IT) Conversion)..Page no (2-341

The entered character is:

Program for bitmap character generation

the characters using Bit Map


A 'C Program to generate 1 1

method
1

#include <stdio.h>
#incude<conio.h> 1111 1
1
#include<graphics.h>

Void main()0 1 1

int gd. gm, al[7]15)


={0},i, j;
1

gd DETECT ImportantQuestions
initgraph(&gd,
gm,"C:/TC/BC');
Here we are mentioning some important
crscr0:
from the topic which we have seen.
the array: "); questions
printf("Enter
And also, how to write the answers for these
fori-0;i<7;i++)
questions.
We are not writing
the full answers

for the questions, but


we are insisting students
fortj 0j<5j++)
to write the answer in his/her
own words, and
Scanf od",&a[ilb):

)
to the that
for that we are providing guidelines
with the help of those
answers. So that,
can write his own
printf("The
entered character isin or points, student
guidelines
forfi=0;i<7;it+) answer.

forj=0j<5;j++) Q.1 Explain


DDA line generation algorithm.

Ifa[bl==1) The answer should include following


Ans.: for this question
printf
d", alibl);
points
else - Gentle slope and steep slope.
printf(" 0" How to find next pixel
from the current point?

print(" In *);
Ceiling and flooring functions.

Steps for DDA line generation algorithm


with diagram

of all cases such as gentle slope and steep slope lines.


Output State advantages and disadvantages of algorithm.

Enter the array of


Take a suitable example and explain it by steps

0 0 1 0 0 algorithm.

0101 0 10 Draw the necessary diagrams whenever possible.

0 0 1 Q.2 Explain Bresnham line generation algorithm.

Ans.: The answer forthis question should include following

100 01 points

Gentle and steep slope


1 0 0 0 1
If possible,derivation of decision parameter.
10 0 0 1 i.e. Gnew = Gola+2Dy and
Gnew Gold +2Dy -2Dx
Steps for Bresenham line drawing algorithm.

w.e.f academic year 20-21) (P4-28)


(SPPU-New Syllabus Tech-Neo Publications..A SACHIN SHAH Ventu
Computer Graphics (SPPU-Sem.4-IT)

a.3
Draw

State
the

Take an example and

its

Explain
diagrams wherever

Bresenham
explain

advantages and disadvantages.


possible.

it
by algorithm.

or midpoint circle
generation
Sr.
No.

3.

4.
Slower

Use of
DDA

than
(Scan Conversion)...Page no

Bresenham Faster
Bresenham

than DDA
(2-35)

I
Unit

In Sem.

algorithm. multiplication and Use of only Addition


we should include division and
Ans.: To answer this
question
operations. Subtraction
following
operations.
points

Definition and equation of circle. 5.


Todisplay pixel we need No need of floor or
of with diagram.
to use either floor or ceil ceil
Symmetry property circle function for
function.
Calculation of decision display.
parameter for circle with
diagrams. 6. Because of floor and ceil No error is
component
of initial function
Derivation decision
parameter with diagram. errorcomponent introduced.

is introduced.
Steps for circle generation algorithm.

Explain the algorithm with suitable and 7. The co-ordinate location


example The co-ordinate
diagram. is same as that same asthat
of| location is

a.4 and Bresenham. of DDA.


Explain aliasing antialiasing techniques.
Ams.:For this we have to include followingpoints:
ImportantLaboratory Assignments
Definition of aliasing and antialiasing.

List aliasing and antialiasing techniques and explain This chapter is important from practical
them in 34 lines with diagrams. examination point of view. We have already
Q.5 Write a explained and
given, enough number of
short note on Normalized device co-
attime of explaining algorithms. In
ordinates.
programs the
addition to these
programs, in final practical
Ans: Answer for this question should include following examination, few modifications are also
points expected. The list of such programs is given
below
Size of screen in NDC with diagram
1. a temple by using DDA
Write program to drawa
Explanation of conversion formulas from NDC to line generation algorithm.
screen co-ordinates and vice versa. 2. draw house by
Write a program to
using
line
Take an example to explain the working of NDC. bresenhams generation algorithm.
3. Write a program to draw a car by using
Explain the limitations of NDC and different bresenhams circle and line algorithm.
techniques to overcome them. 4. Write a program to slide the circle on slanted
the circle and the line for ramp
Draw suitable diagrams wherever possible. ramp. Accept

a.6

Ans.:
Compare
algorithm.

Comparison
DDA

between
Ine algorithm

DDA and
with Bresenham's

Bresenham
line

line
from user.

Q
5. Write a program to generate following shapesby
drawing algorithms
using any circle generation algorithm.
DDA Bresenham
No
And
Based on increment Based on increment

method. method.

Use Use only integers.


floating point
arithmetic.

w.ef academic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
PPU-New Syllabus
(Scan Conversion)..Page no (2-36)
Computer Graphics (SPPU-Sem.4-1T)
and x, > X
6. IfIDxl> IDyl
6. Write a program to generate a spiral circle.

Then the decrements 1 and


-m are used to
generate

new point.

increment
T
Yinctement
-m
are very simple to See Fig. 1(a)
Above mentioned programs
are required to
implement only few modifications

nomal algorithms. Students are advised to make


practice of these assignments. a
Exercise

Q.1 Write the DDA line drawing algorithm. Calculate the

pixel co-ordinates of line AB using DDA algorithm.

Where A = (0.0) and B = (4.6). Fig. 1(a)


(10 Marks)
Ans :Digital differential analyzer (DDA) is based on 7. Similarly if Dxl < IDyl and y, <y
incremental method. The slope for a
intercept equation Then the values of increments in x and y-direction are
straight line is,
1/m and 1
respectively.

m x+b Refer Fig.


1(b)
Where m is slope and b is
y-intercept. We can
determine the value of m as,
X
Incrementm

Steps for DDA algorithm a Yincrement1


1.
Accept two end points: (%, y)and (xp, y)
2 Find out horizontal and vertical difference between end
oints. Fig. 10b)

Dx p-X and
Dy=y»-y 8. Similarly if IDxl < IDyl and y,> ys
3. between Then
Difference the values of increments in x and
greater magnitude determines the y-direction are
value of parameter steps.
and
m 1.
4. Determine the offset needed at each step i.e. to generate
the next pixel loop Refer Fig. 1(c).
through this step times.

5. 1fIDxl> and
IDyl
x,<p Ya

Then the values of the increments in the x and y


directions are 1 and m respectively. See Fig. 1. Increment

Kincrement l, Yincrementmn Yb increment


-1

Aa
b
Fig. 1)
a

Fig. 1
Example:Pixel

,
Suppose

Dx= -x,)=x(4-0)=4
if

So, =0.y, =0, =4 and y,

Dy=(2-Y,)=(6-0)=6
calculation

we want to
for a
Line AB.
draw a line from

=6.
(0,0) to (4,0)

(SPPU-New Syllabus w.efacademic year20-21) (P4-28)


Tech-Neo A SACHIN SHAH Ventur
Publications
Computer Graphics (SPPU-Sem.4-IT

As IDxl <IDyl the line

Steps
is
of Steep slope
abs (Dy)

Dx 4/6 =0.6
4/6 =0.6
category.

=6
(XY
From the given
(Scan Conversion) ...Page no (2-37)

Aincrement

information
D-3/6
steps
=0.5

we can put first point


i.e.
I
Unit

IuSem.
Ancroment

incremen
steps

Dy 6/6 =
steps
1
new Kold increment
=2+ ] 3
Ynew Yold+ Yincrement=
3+0.5 =3.5
First point we know i.e. X. Y1 so plot it.
But here we have to round off 0.5 as 1 for displaying

new odKincremeni =0+0.6 = 0.6 that point i.e. per display is (3. 3.5).

new oid =0+1 = For next iteration


11
Tincrement

we
But over here have to round off 0.6 as 1 for Anew Xold +Xincrement3+1=4
that point.
displaying new Yold Yincrement 3.5 +0.5=4
For next iteration
Next point for display will be (2, 1) Now loop steps

Apew Aoldt Ancremen=0.6+0.6 = 1.2 are tabulated as follows.

mew VodYincrementI +l=2 Display


Now loop steps are tabulated as follows 2 32.3
Plot L3 3.5 3,4
4 4 4,4

2
3
0.6-1

1.2
0

1
0

2
0,0

1,1

1,2
8
6
7
4.5

5
5.5

6
5.5
6,5
7.6
1.8-2 2,3
86
Q. 3 Rasterize the line from(-6, 5) to (1, 0) using
2.4-2 2,4 Bresenham's line drawing algorithm.

3,5 (Q. 1(a), May 19, 6 Marks)


Ans.:

7 3.6-4 6 4,6
Solution: =-6, y, =-5x2=1, Y2=0
For
for display
calculation

we
purpose we are
are rounding the values.
using original

If
value but
we do this
D = a-x,l=
lya-yl =
Given:

=7
=5
I1
X
-(-6)!

till e
the desired
and
only,

ynew

line.
becomes same as end point then we will get
D,
G
10-(-5)1

2D,- D, =2(5) 7 = 10-7


- 3
Let's plot 1" point as (-6, -5)
Q.2 Interpret Digital Differential Analyzer (DDA),
Since
algorithm to find which pixels are turned on for the ID,>ID,I the line is of Gentle slope category

line segment between (2, 3) and (8, 6). So we have to move along x till x, i.e. 1

After ploting I" point as (-6,-5),


(.2b), May 18, 6 Marke) increase x by 1.

Ans. x becomes equal to -5

Given: x, =2, y,
=3, x=8, y2=6 Here, G>0
DX=-X1)=(8-2)=6 So update y by 1 because y, < ya and
modify G as

DY =U-Y)=(6-3) -3 G = G+2(D,-D,)
As IDXI> IDYI the line is gente slope category
= 3+2(5-7)=3+2(-2)
steps= abs (DX)=6 3-4-1
poreent
DE 6161 Plot next point as
(-5,-4)
steps
Now again update x by 1, x becomes -4, Here G=-1

(SPPU-New Syllabus we.facademic year 20-21) (P4-28) Tech-Neo Publications..A SACHIN SHAH Venture
(Scan Conversion)...Page
no(2-38)

Computer Graphics
(SPPU-Sem,4-1T) X Y
G as,
So don't update y and update -4 4
G = G+2 Dy =-1+2(5)=9 x
Plot next point as (-4, 4). Go
on doing this till
-3 -3
becomes -2
-2
-6,- 3) to
xA

Hence we on a line
get following points
-1 -2
1.0
X Y 0 -1

Chapter Ends...
O00

You might also like