2. Scan Conversion
• Last step in the graphics pipeline
• Efficiency is a central issue
• Common primitives
– Lines
– Polygons
– Circles
• Hardware implementations preferable
3. Lines
• Compute the coordinate of the pixels that lie on a
line on a 2D raster
• Defined by the coordinates of the end points
• Criteria
– Thin
– As close to ideal as possible
– 1 pixel wide
• If -1<= slope <= 1 exactly 1 pixel in one column
• Else exactly 1 pixel in one row
– Constant brightness, independent of the length &
orientation
– Should be drawn fast
8. Basic Incremental Algorithm
• Brute force algorithm
• Inefficient
• Each iteration
– Floating point multiply
– Floating point addition
– Rounding
{
)
,
,
,
( 1
1 y
x
y
x
Line 0
0
;
1
1
0
0
x
x
y
y
m
){
;
; 1
i
i
0
i x
x
x
x
for(x
);
( b
mx
Round
y i
i
}
}
);
,
( i
i y
x
drawpixel
9. Basic Incremental Algorithm
• Eliminate the
multiplication
• Incremental
computation
• Digital Differential
Analyzer (DDA)
b
mx
y i
i
1
1
}
}
;
));
(
,
(
){
;
;
;
;
{
);
,
,
,
(
1
1
1
1
1
m
y
y
y
Round
x
drawpixel
x
x
x
x
for(x
y
y
x
x
y
y
m
y
x
y
x
Line
i
i
i
i
i
i
0
i
0
i
0
0
0
0
m
y
y
then
x
If i
i
1
1
b
x
x
m i
)
(
x
m
yi
b
mx
y i
i
10. Basic Incremental Algorithm
• If the magnitude of the slope is more than 1 change
the role of x and y in the algorithm
– y increases faster than x
• Simple but inefficient
– Still there are floating point operations
• Bresenham’s algorithm
– Uses only integer arithmetic
– Avoids round function
– Extended to drawing circles
11. Midpoint Line Algorithm
1
1
m
Assume
(NE)
NorthEast
(E)
East
choices
Two :
right
upper
:
y
x
left
lower
:
y
x
)
,
(
)
,
(
1
1
0
0
)
,
(
: p
p y
x
pixel
Previous
next?
be
should
pixel
Which
E
NE
M
Previous
Pixel
Current Pixel
Choices
Next Pixel
Choices
)
,
( p
p y
x
P
Q
12. Midpoint Line Algorithm
y
x
pixel
Previous p
p )
,
(
:
• Compute the distance between
– Q and E
– Q and NE
• See which side of the line M lies
• M lies below the line
– Choose NE
• M lies above the line
– Choose E
• M lies on the line
– Choose either
1
p
x
x
with
line
the
of
on
intersecti
of
Point
:
Q
E
NE
M
Previous
Pixel
Current Pixel
Choices
Next Pixe
Choices
)
,
( p
p y
x
P
Q
16. Midpoint Line Algorithm
value
the
in
change
the
on
based
Add
directly
F(M)
of
value
the
compute
not
Do
• What happens at the next grid point?
– Depends on whether we choose N or NE
• If E is chosen
c
y
b
x
a
y
x
F
d p
p
p
p
new
)
2
1
(
)
2
(
)
2
1
,
2
(
c
y
b
x
a
d p
p
old
)
2
1
(
)
1
(
a
d
d old
new
dy
a
d
d old
new
E
E)
choose
we
after
d
in
increment
E (
E
N
E
M
Previo
us
Pixel
Current
Pixel
Choices
Next Pixel
Choices
)
,
( p
p y
x
P
Q
17. Midpoint Line Algorithm
• If NE is chosen
c
y
b
x
a
y
x
F
d p
p
p
p
new
)
2
3
(
)
2
(
)
2
3
,
2
(
NE)
choose
we
after
d
in
increment
NE (
c
y
b
x
a
d p
p
old
)
2
1
(
)
1
(
b
a
d
d old
new
dx
dy
b
a
d
d old
new
NE
value
the
in
change
the
on
based
Add
directly
F(M)
of
value
the
compute
not
Do
E
N
E
M
Previo
us
Pixel
Current
Pixel
Choices
Next Pixel
Choices
)
,
( p
p y
x
P
Q
18. Midpoint Line Algorithm
• Summary
– Choose between the two pixels (E/NE) based on
the sign of the decision variable d=F(M)
– Update the decision variable by adding the change
along that direction
– Repeat this process until the end point is reached
19. Midpoint Line Algorithm
2
dx
dy
d
variable
decision
the
for
value
Initial
)
2
1
,
1
0
0
start y
F(x
F(M)
d
c
y
b
x
a 0
0
)
2
1
(
)
1
(
2
b
a
c
by
ax 0
0
line
the
on
lies
)
,y
(x
since
b
a 0
0
2
20. Midpoint Line Algorithm
• Fractional arithmetic still problematic
• Should be avoided if possible
• Redefine F(x,y) by multiplying by 2
• Thus F(x,y) = 2(ax+by+c)
• Replace all constants and the decision variable
by 2
• Removes all multiplications; only additions left