You are on page 1of 27

Computer Graphics & its Applications

Subject Code: CSE -710

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
2

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 Graphics
Donald Hearn, M. Pauline Baker
Computer Graphics: Principles and Practice
J. D. Foley, A Van Dam, S. K. Feiner, and J. F. Hughes

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

Computer graphics

Concept

Model

Image

The core technological issues in computer generated imagery.

Modeling

Concept

Model

Image

MODELS (in computer graphics): A Digital, Descriptive or


Mathematical representation of a scene or object that can be
stored (efficiently) in computer memory.
6

Rendering

The rendered IMAGE is a visual representation of the


model on digital output media.

Graphic Devices

Display system where the graphics are rendered

in the console screen of the computer


H/W components with which user interacts to
generate necessary instructions for the creation
of graphics

Devices

Keyboard
Mouse
Joystick
Trackball and Trace ball
Digitizer
Scanners
Touch Panels
Light Pen
Voice System
9

Introduction

Pixels
Straight Lines
Line Drawing algorithms, straight
Digital Differential Analyzer DDA
Bresenham

Second order Curves


Mid point Algorithm

10

Pixels

A pixel is the basic entity in computer graphics


Represents a 0-dimensional geometric point at

position (x,y) with zero length, zero area, zero


volume,
A pixel has several properties

Pixel position(Xint, yint) = (round(x), round(y)) where


round(x) =(int)(x+0.5)
Colours(R,G,B)
Intensity
Has non-zero extension
11

Pixel Coordinate Systems

12

Straight Lines

A straight line , say s, has two end points, say

p1, p2 and a collection of points connecting the


two end points.
Geometrically a line is defined using the
parametric representation
S = p1 + t*(p2-p1), t [0,1]
Or an equation with constants a,b,c and
end points:
A*x + b*y + c = 0 and p1,p2

13

Line drawing Algorithm

Using the line equations


DDA Algorithm
Bresenhams Line drawing Algorithm

14

Line Equation
The equation of a Line is given by
y = mx + b . (1)
Rearranging we get
b = y mx ---------------------(2)
where m = (y2-y1) / (x2- x1) = dy/dx y/x
For any given small x interval x along the line, compute the
corresponding y interval i.e.
y = m x --------------------- (3)
Similarly for any given small y interval y along the line, compute the
corresponding x interval i.e.
x = y / m---------------------(4)

15

DDA Algorithm
Y

(Xk+1,Yk+1)

(Xk, Yk)

16

DDA

This is an incremental Scan conversion line

drawing algorithm based on calculating either

y or x .

Sample the line at unit intervals in one co

ordinate and determine the corresponding


integer values nearest line path for all the other
co ordinates

Case :1 If |m| 1

X k+1 = Xk + 1
Yk+1 = YK + m
Case :2 If |m| > 1
Yk+1 = Yk + 1
Xk+1 = XK + 1 / m

17

DDA

Case :3 If |m| < 1 and start point is on the right

hand side
X k+1 = Xk - 1
Yk+1 = YK - m
Case :4: If |m| > 1 and start point is on the
right hand side
Y k+1 = Yk - 1
Xk+1 = XK 1/ m

18

Assignment Problems
1) 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 line
whose end points are (2,3) , (5,9).
3) Consider a line from (0,0) to (5,5), use DDA to rasterize
the line.
4) Write a pseudo code to describe the DDA for scan
converting a line whose slope is between
a) -45 deg and +45 deg
b) 45 deg and -45 deg
3) Consider a line from
a) (0,0) to (-8,-4)
b) (1,1) to (8,5)
c) (0,0) to (5,5)
use any line drawing algorithm.
19

Bresenhams Line drawing Algorithm

Initial
pixel

(Xk,Yk)

(12,12)

Next Pixel

Either

or
(Xk+1,Yk+1)
(13,13)

(13,12)

Xk+1

Next
Yk+1
Y

d1

(Yk+1)

(Yk)

d2

Yk

or

Either

Yk+3
Yk+2
Yk+1
Yk

Xk

Xk+1

Xk Xk+1Xk+2 Xk+A
20

Bresenhams Line drawing Algorithm

Testing the sign of an integer parameter whose value is


proportional to the difference between the two pixel
position from the actual line.
Consider a line with |m| < 1, pixels positions along a line
are determined by sampling at unit x intervals.

21

Bresenhams Line drawing Algorithm


The y co ordinate on this sampling line w.r.t pixel column
positions xk + 1 is calculated as
y = m.(xk+ 1) + b
Then d1 = y yk = m.(xk+1) + b yk
d2 = (yk + 1) - y
= ( yk + 1) [ m.(xk+1)+b]
If d1 < d2 , next point is (xk+1, yk)
If d1 d2 , next point is (xk+1, yk+1)
The difference
d1 d2 = m(xk +1) + b yk [(yk+1) m.(xk+1) - b]

22

The difference
d1 d2 = m(xk +1) +b yk [yk+1-m(xk+1)-b]
= 2m(xk+1) + 2b - 2yk 1
= 2.(y/x).xk - 2yk + 2b + 2.(y/x) 1
Let Pk be the decision parameter for the kth step in the line
algorithm. Then
Pk = x.(d1-d2) , x > 0
= x. [2.(y/x).xk - 2yk + 2b + 2.(y/x) 1]
= 2y.xk - 2x.yk + C
(1)
Where C = 2y + x(2b 1)
Contd

23

So, at the step K+1, the decision parameter is given by


Pk+1 = 2y.xk+1 - 2x.yk+1 + C
(2)
From (1) & (2), we may get
Pk+1 - Pk = 2y.(xk+1-xk) - 2x(yk+1-yk)
But Xk+1 = Xk + 1, so that
Pk+1 = Pk + 2y.(xk +1 -xk) - 2x.(yk+1-yk)
= Pk + 2y - 2x.(yk+1-yk), where (yk+1-yk) is
either 0 or 1 depending Pk.
if Pk < 0 then yk+1 = yk so that
Pk+1 = Pk + 2y and next point is (xk+1, yk)
if Pk 0 then yk+1 = yk + 1 so that
Pk+1 = Pk + 2y - 2x and next point is (xk+1,yk+1) or
(xk+1, yk+1)
24

Starting decision parameters:


Let at the start point (x0, y0), the equation of line is
Y0 = mx0 + b
Hence
P0 = 2y.x0 - 2x.y0 + 2y + x.(2b 1)
= 2y.x0 - 2x.(mx0+b)+ 2y + x.(2b 1)
= 2y.x0 - 2y.x0 - 2x.b+ 2y + 2x.b x
= 2y x

25

Prob. Find out the pixel coordinates of a line from


(10,15) to (20,23)
y = dy = 23-15 = 8,
x = dx = 20 10 = 10
Starting decision parameter :
P0 = 2y x = 2.8 10 = 16 -10 = 6
Hence,
2. y = 2.8 = 16 and
2. (y x) = 2. (8 -10) = 2. (-2) = -4

26

P
6=6
6+(-4)=2
2+(-4)=-2
-2+(16)=14
14+(-4)=10
10+(-4)=6
6+(-4)=2
2+(-4)=-2
-2+(16)=14
14+(-4)=10

(x,y)
(11,16)
(12,17)
(13,17)
(14,18)
(15,19)
(16,20)
(17,21)
(18,21)
(19,22)
(20,23)
27

You might also like