Lecture 03 - Scan Conversion
Lecture 03 - Scan Conversion
Viewport
Rasterization
Transformation
Rasterization
• Circles
• Triangles
• Polygons
Scan Converting a point
Each pixel on the graphics display does not represent a
mathematical point. Instead, it means a region which
theoretically can contain an infinite number of points. Scan-
Converting a point involves illuminating the pixel that contains
the point.
(4.3,3.3)
Scan Converting a line
Line drawing is accomplished by calculating intermediate
positions along the line path between two specified end points.
Scan Convert a Vertical/Horizontal
Line
Line 1: (0,0),(4,0)
Line 2: (4,0),(4,4)
(0,0) 4
Basic Line
Algorithms
• Lines must create visually satisfactory images.
• Lines should appear straight
• Lines should terminate accurately
• Lines should have constant density
• Line density should be independent of line length and angle.
• Lines sharing vertex should avoid/minimize overlap
• Lines sharing vertex should avoid/minimize gaps!
• Line algorithm should always be defined.
Line Drawing Algorithm
8
7 Line: (3,2) -> (9,6)
6
5
4
? Which intermediate
pixels to turn on?
3
2
1
0 1 2 3 4 5 6 7 8 9 10 11 12
Direct use of the Line equation
(x1,y1)
dy
(x0,y0)
dx
Line Drawing Algorithm
• DDA Algorithm
• Bresenham’s Line Algorithm
DDA Algorithm
• Digital Differential Analyzer is an algorithm for scan-
converting lines
• It calculates pixel positions along a line by taking
unit step increment along one direction and
calculating corresponding coordinate position based
on the rate of change of the coordinate
DDA Algorithm
Given two end points (,), (,)
𝑚= 𝑦 2 − 𝑦 1
𝑥 2 − 𝑥1
(,)
(,)
(,)
DDA Algorithm
Various
Cases
xn = x1 + 1
|m|<1 yn= y1+ m
xn= x1 +
|m|>1 yn= y1 + 1
xn = x1 + 1
|m|=1 yn= y1 + 1
DDA Algorithm
Example
two end points
(,), (,)
(,)
Slope,m =
=
(,
=
= 1
DDA Algorithm
two end points (,), (,)
As m=1,
x n = x1 + 1
(,)
yn = y1 + 1
x1 y1 xn yn
2 4 2+1=3 4+1=5
(,)
(,
DDA Algorithm
As m=1,
xn = x 1 + 1
yn= y1 + 1
(,)
(,)
x1 y1 xn yn
(,)
2 4 2+1=3 4+1=5
(,
3 5 3+1=4 5+1=6
DDA Algorithm
As m=1,
xn = x 1 + 1
yn= y1 + 1
(,)
(,)
(,)
x1 y1 xn yn
(,)
2 4 2+1=3 4+1=5
(,
3 5 3+1=4 5+1=6
4 6 4+1=5 6+1=7
DDA ALGORITHM
As m=1,
xn = x 1 + 1
yn= y1 + 1
(,)
(,)
x1 y1 xn yn
(,)
2 4 2+1=3 4+1=5
(,)
(,)
3 5 3+1=4 5+1=6
(,
4 6 4+1=5 6+1=7
5 7 5+1=6 7+1=8
DDA Algorithm
As m=1,
xn = x 1 + 1
yn= y1 + 1
(,)
(,)
x1 y1 xn yn
(,)
2 4 2+1=3 4+1=5
(,)
(,)
3 5 3+1=4 5+1=6
(,
4 6 4+1=5 6+1=7
5 7 5+1=6 7+1=8
6 8 6+1=7 8+1=9
DDA Algorithm
Slope,m = = = = 0.57 ≈ 0.6 Consider endpoints:
(0,0), (7,4)
As m<1,
xn = x1 + 1
yn= y1+ m
x1 y1 xn yn
0 0 0+1=1 (6,4) (7,4)
0+.6=.6 ≈1
1 1 1+1=2 .6+.6=1.2 ≈ 1 (4,2) (5,3)
2 1 2+1=3 1.2+.6=1.8 ≈ 2 (2,1)
(3,2)
(1,1)
3 2 3+1=4 1.8+.6=2.4 ≈ 2
(0,0)
4 2 4+1=5 2.4+.6 = 3
5 3 5+1=6 3+.6=3.6 ≈ 4
6 4 6+1=7 3.6+.6=4.2 ≈ 4
Thank You