CG Unit 1 Tech-Neo
CG Unit 1 Tech-Neo
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
Pune.
Maharashtra, India
LECHNEO
PUBLICATIONS
huovalion
P4-28
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
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
Course Outcomes:
On completion ofthe course, students will be able to-
co3: fromaworld coordinates to device coordinates, cliping. and projections in order to produce 3D
Describe mapping
cOURSE CONTENTS
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)
Polygons: Polygons and its types, inside test, Polygon filling methods: Seed Fill -Flood fill and Boundary Fill, Scan
2D Transformations Translation, Scaling, Rotation, Reflection and Shearing, Matrix representation and
Unit IH:Windowing,
Windowing :Concept
CIlpping,3D
of window and
Transformation,
vie
Projectlone
:
Polygon Clipping for convex and concave polygon clipping.
Ilumination models: Light sources, ambient light, diffuse light, specular reflection, the Phong model, combined
Color Models: CIE Chromaticity Diagram, Color Gamut, RGB, CMY, YCbCrHSVeolormodels.
Shading Algorithms: Constant intensity shading, Halftone, Gourand and Phong Shading.(Refer Chapters 7and 8)
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.
I's
06
services
of virtual
for character expressions.
Rendering Pipeline: Graphics rendering Pipeline, Haptics Rendering Pipeline Modeling in Virtual Reality: Concepts
of Geometric Modeling, Kinematic
Modeling, Physicalmodeling and Behavior modeling.
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
UNIT N
Chapter 5: Windowing and Clipping.. ..5-1 to 5-33
UNIT IV
Chapter 7 Segments. ..7-1 to 7-11
UNIT V
Chapter 9 Curves and Fractals... ....9-1 to 9-18
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
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..
*** 1-4
Topic:Pixel, Frame Buffer.********
****°******** ss**
************°***°***°*****°. ******** ****************
Syllabus
**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
***** **************
*
}-11
******************'"***'"'****°''***********'******.*i*'*'1
1S Primitve Operahons
*
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******
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
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
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
and efficiently transferred between machine by working at one diagram we can answer many
effectively
(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.
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
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
Process Controlling.
stores pixel values for use by the
5 7T8 9 display device.
10
(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
transparency.
displays
buffers
that were
differ
common
significantly
prior to
from the
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
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
animation.
D. Acceleration
(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
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
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
C. Refresh rate
A. Text mode/character mode
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.
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()
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
(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
1.3.3 Aspect Ratio original film. To avoid this loss we preferring letterbox
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
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
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
0
electrons.
Vector Refresh varies from one type of phosphor to another. The light
Display
given off by the phosphor during exposure to the
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.
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
(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
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
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
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
pixels is called as
framë buffer.
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
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.
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
the wires that intersect the desired point. To make pixel display.
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
display device?
-* -** ***-********
(SPPU-New Syllabus w.e.f academic year 20-21) (P4-28) Tech-Neo Publications...A SACHIN SHAH Venture
(BasicPrimitives)..Page no(1-12)
final point.
X,Y
DY
Fig. 1.5.1
DX
If we want to join another line BC to this line segment Current
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.
Fig. 1.5.5
:
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
Current
Fig. 1.5.6
position
e.g. I Sem.
1.6 DISPLAY FILE ANDITS STRUCTURE
Opcode (oP)array X-op arrayY y-0parrayY
In
The file in which we are storing these commands to op [2]. x-op [2], y-op [2].
command and opcode 2for Line command. where 1 means Move command
)
Fig. 1.6.1
(
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)
y2)
BX2.Y2
XY
Fig. 1.6.5
Fig. 1.6.2
Now our display file for this rectangle ABCD will look like.
(2.X Ys) 2
where 2stands for line command.
2
Now this display file is containing what to display on
screen.
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
Display file
interpreter serves as an interface between
our
graphics program and the
display device.
1. Raster scan
1.7.1
scan devices heavily.
right. This defines a scan line. Very high resolution, limited only by monitor.
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
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
|
is
Pen plotters and direct Cathode vertical axis and 3 units away from the horizontal
ray tubes (CRT) axis.
controlled.
processor
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
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
(-1.5,+2.5
a processing pipeline. Some commands specify
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
.
negative coordinates. Accordingly
Ist operations
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
function calls which can be used addresses and associated values using a two
to draw different
of
stored z values (for z buffering) and blending objects.
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
.
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
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
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.
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
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
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.
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
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.
**************""********************"
********************°***********************"********************
*****************************************************
************a****t***eosstssdsatssossens.G
.2-2
Z-3
.2-3
.2-4
C
2
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.
**** *********************************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.7
CharacterGeneration.. 2-32
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
Scan conversion.
we use right
handed coordinate system,
Normally
( 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
GQ DefineLine
-
Segment.
****--*
I
*******a-* *********. InSem
There is a difference between line and line
segment. Y1
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
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
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)
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
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.
algorithms.
Line Generation
Algorithms
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.
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
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
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
(y+1)-(y,)=nm (1)
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
y
y2
1
L
X=1 x=2 3
Fig. 2.3.9
4 5
For
When the slope (m) is = 1 then as x changes, values of
integer.
will return 9.
Ynew Yold+1 and *new which is less than or equal to its If the value
Kold + 1 argument.
(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
Then the
if IDxl<IDyl
3.
Dx AX
points.
Difference between
and Dy
greater
= yh
- y.
Increment-1
m
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>
and yincrement
2-I
a Main
Function Name
Purpose To initialize graphics mode and eallDDA
a function
Fig 2.3.11
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");
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
akgorthm
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?
direction
xine=(oat)dx/steps;/calculate
yineoet)dy/steps;
the increment
2.3.1
****
GQ. What
-
(c) Disadvantages of
algorithm?7
putpisel (xy,WHITE); plot first point/ the calculated pixel position to drift away from the true
Dx (x^-X)=(5-1)=4
Dy (a-y)=(3- =2 1)
increment
abs (Dx)
D=0.5
steps
=4
As IDxl> 1Dyl
Steps=
Increment
abs (Dx) =4 I
Unil
n Sem.
Yincrement steps
steps
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
6
For
for display
If
calculation
we
only,
do
we are
this
purpose
till
xpew
we are
rounding the values
and ynew
using original
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).
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
.
1" point as (0,0) increasexby
=
1.
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
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
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
Steps = abs (Dy) =5 0.5 then we are selecting next pixel as (1,0).
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
to y2 i.e. 6
equal
Fig.2.3.155
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)
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&
Now if
G+D
2 Dx
we consider P
P
=P+ then
value and add (2Dy
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;
XoYo closegraph0:
..
dx = dys
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.
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
Fig. P. 2.3.5
int sign(loat arg)
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.
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
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
X 5, Y=2
Xa 8, Y2=4
Dx=X2-X1 =3
Dy Y2-Y1 =2
G 2Dy- Dx =2 (2) - (3) =
.
1
I
Unit
1
6 i.e. G>0
> y2 and modify G as
In Sem.
Here G= 1
update y - by
1 because y1
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
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
(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
3
G
Plot 1 point (2. 2) here as IDxl> IDy! that means line is
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.
D 6 -0 =6
= h.- yl= Here G 0.
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,
.
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)
. D
10;
= X2-X1 =10-20 =- 10
Y2
points
Solution:
are (3, 2) and (10, 8). In Sem-
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
.
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
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.
9
4.55 6,5
G by,
Next time don't
G
increase
18
20
19
18
19
20
increment Steps
D Steps
=057
abs(D,) =7
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,
x
need to round off
to(9,5)
.
that point
The followingtable 8 6
XY|
10 10
summarizes the
Plot
points.
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
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
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
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.
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
X 4 YDisplay
Here G=0
We have to increase y by 1 and update G as,
-2-1 2,-1
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
.
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.
( 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
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.
Syllabus Topic: Circle DrawingAlgorithm size. The step size chosen for 6 will depend on
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)
.
(x.y)
GQ.Explain Midpoint circle generating algorithm?
******* ******* *******^.* * *o-~--..
Here we have to determine the closest pixel position 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
this (x. y) we will plot rest seven points as (x, y). (y. x), function.
becomes fast.
(x.y)
(0,0)
Fig. 2.4.5
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.
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.
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
circle function.
--
or P
Therefore
fcince +
we will
1,Y-1)
take midpoint of these two points as,
Ifradius r
Clrcde Generation
P face+1,%-12) Algorichmn
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
increase x by 1
i.e. when, earlier we have changed row.
and decrease y by 1
g:Yo)= (0, r). See Fig. 2.4.7. 3. Since we have derived all formulas by considering
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
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);
== 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);
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.
Plot (0, 3)
Like that find out other points from (0, 3) by using
symmetry property
So plot (3, 0)
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
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:
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
Yn-
Yn-1-
2 Fig.2.4.9
(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)
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.
(+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
=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,
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' variable to
Here, we are making use of just
determine which draw.
sign of
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.
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>
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
..
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,
:
enter the radiusof the circle
150
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
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.
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.
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
It
requires large number of calculations and
approximations. Prefiltering generates more accurate
2.5.2 Antialiasing 2.
******* Supersampling
a ultimately pixel
becomes the of
average several
2.5.2(A) Antialiasing Methods samples.
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
(1,0) (1,1)
can be as
displayed
Height
Fig. 2.5.8
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
In normalized co-ordinates
GQ. What is a Normalized
Device Coordinates?
the screen is 1 unit wide but
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
normal
Yenheightstart
0.5,0.6 height
'
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
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.
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
3. Starbust method
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
A
image properly
AA
proportional but we are wasting the area.
display
Fig. 2.7.1
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
copying characters
image from font cache into the
frame buffer at the desired position.
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
method
1
#include <stdio.h>
#incude<conio.h> 1111 1
1
#include<graphics.h>
Void main()0 1 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
)
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.
print(" In *);
Ceiling and flooring functions.
0 0 1 0 0 algorithm.
100 01 points
a.3
Draw
State
the
its
Explain
diagrams wherever
Bresenham
explain
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.
is introduced.
Steps for circle generation algorithm.
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.
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.
new point.
increment
T
Yinctement
-m
are very simple to See Fig. 1(a)
Above mentioned programs
are required to
implement only few modifications
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
Aa
b
Fig. 1)
a
Fig. 1
Example:Pixel
,
Suppose
Dx= -x,)=x(4-0)=4
if
Dy=(2-Y,)=(6-0)=6
calculation
we want to
for a
Line AB.
draw a line from
=6.
(0,0) to (4,0)
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
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).
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
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.
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
line segment between (2, 3) and (8, 6). So we have to move along x till x, i.e. 1
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