1 Computer Graphics & its Applications Subj ect Code: CSE -710
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 1/27
1
Computer Graphics & its ApplicationsSubject Code: CSE -710
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 2/27
2
Course Content• Introduction• Scan Conversion – Lines, Circles, Ellipses:
Filling polygons and clipping algorithms• Two Dimensional Transformations
• Three dimensional Transformations• Projections• Plane Curves and surfaces
• Solid Modeling• Visible Surface Determination
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 3/27
3
Books• Principles of Interactive Computer Graphics
W. M. Newman, Robert E. Sproull• Mathematical Elements for Computer Graphics
D.F. Rogers and J. A. Adams• Computer Graphics
Steven Harrington
• Computer GraphicsDonald Hearn, M. Pauline Baker
• Computer Graphics: Principles and PracticeJ. D. Foley, A Van Dam, S. K. Feiner, and J. F. Hughes
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 4/27
4
• What is Computer Graphics ?• What is image processing ?• Some Applications of Computer Graphics
– CAD/CAM
– Entertainment – Education and Training – Animation/Video Games – 3D Surface Modeling
– Visualization
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 5/27
5
Computer graphics
The core technological issues in computer generated imagery.
Concept Model Image
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 6/27
6
Modeling
Concept Model Image
MODELS (in computer graphics): A Digital, Descriptive orMathematical representation of a scene or object that can bestored (efficiently) in computer memory.
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 7/27
7
Rendering
The rendered IMAGE is a visual representation of themodel on digital output media.
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 9/27
9
Devices
• Keyboard• Mouse• Joystick • Trackball and Trace ball
• Digitizer• Scanners• Touch Panels• Light Pen
• Voice System
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 10/27
10
Introduction
• Pixels• Straight Lines• Line Drawing algorithms, straight
– Digital Differential Analyzer DDA – Bresenham
• Second order Curves – Mid point Algorithm
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 12/27
12
Pixel Coordinate Systems
X
Y
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 13/27
13
Straight Lines
• A straight line , say ‘s, has two end points, sayp1, p 2 and a collection of points connecting thetwo end points.
• Geometrically a line is defined using the
parametric representation –S = p 1 + t*(p 2-p 1), t [0,1]Or an equation with constants a,b,c and
end points:
A*x + b*y + c = 0 and p1,p2
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 14/27
14
Line drawing Algorithm
• Using the line equations• DDA Algorithm
• Bresenham’s Line drawing Algorithm
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 15/27
15
Line Equation
The equation of a Line is given byy = mx + b ………………. (1)
Rearranging we getb = y – mx ---------------------(2)
where m = (y 2-y1) / (x 2- x1) = dy/dx ≈ ∆y/∆x
For any given small x interval ∆x along the line, compute thecorresponding y interval i.e.
∆y = m ∆x --------------------- (3)Similarly for any given small y interval ∆y along the line, compute thecorresponding x interval i.e.
∆x = ∆y / m---------------------( 4)
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 16/27
16
DDA Algorithm
(Xk, Yk)
X
Y
(Xk+1 ,Yk+1 )
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 17/27
17
DDA
• This is an incremental Scan conversion linedrawing algorithm based on calculating either ∆y or ∆x .
• Sample the line at unit intervals in one coordinate and determine the corresponding
integer values nearest line path for all the otherco ordinates
• Case :1 If |m| ≤ 1X k+1 = X k + 1 Y k+1 = Y K + m
• Case :2 If |m| > 1 Y k+1 = Y k + 1Xk+1 = X K + 1 / m
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 18/27
18
DDA
• Case :3 If |m| < 1 and start point is on the righthand side
X k+1 = X k - 1 Y k+1 = Y K - m
• Case :4: If |m| > 1 and start point is on theright hand side
Y k+1
= Y k
- 1Xk+1 = X K – 1/ m
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 19/27
19
Assignment Problems1) Using DDA line drawing algorithm find the pixel co-
ordinate to draw a line from (2,3) to (9,7).
2) Find the Pixel co-ordinates using DDA to draw la linewhose end points are (2,3) , (5,9).
3) Consider a line from (0,0) to (5,5), use DDA to rasterizethe line.
4) Write a pseudo code to describe the DDA for scan
converting a line whose slope is betweena) -45 deg and +45 degb) 45 deg and -45 deg
3) Consider a line froma) (0,0) to (-8,-4)b) (1,1) to (8,5)c) (0,0) to (5,5)
use any line drawing algorithm.
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 20/27
20
Bresenham’s Line drawing Algorithm
Initialpixel (12,12)
(13,12) (13,13)
Either or
Next
(Xk,Yk)
(Xk+1 ,Yk+1 )Either
Next Pixel
Xk+1
Either or Either or Either or Either or Either
(Xk,Yk)
Next Pixel
(Xk,Yk)
(Xk+1 ,Yk+1 )
Next Pixel
(Xk+1 ,Yk+1 )
Next PixelNext PixelNext Pixel
(Yk) (Yk+1 )Either or
Xk Xk+1
Yk
Yk+1
Y
d1d1
d2
Xk Xk+1Xk+2 Xk+A
Yk
Yk+1
Yk+2
Yk+3
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 21/27
21
Bresenham’s Line drawing Algorithm
• Testing the sign of an integer parameter whose value isproportional to the difference between the two pixelposition from the actual line.
• Consider a line with |m| < 1, pixels positions along a lineare determined by sampling at unit x intervals.
8/10/2019 Computer Graphics Lec_1
http://slidepdf.com/reader/full/computer-graphics-lec1 22/27
22
Bresenham’s Line drawing Algorithm
The y co ordinate on this sampling line w.r.t pixel column
positions x k + 1 is calculated asy = m.(x k + 1) + b
Then d 1 = y – y k = m.(x k +1) + b – y k
d2 = (y k + 1) - y
= ( y k + 1) – [ m.(x k +1)+b]If d 1 < d 2 , next point is (x k +1, y k )If d1 ≥ d2 , next point is (x k +1, y k +1)
The differenced1 – d2 = m(x k +1) + b – y k – [(y k +1) – m.(x k +1) - b]