Professional Documents
Culture Documents
Dda Circle
Dda Circle
Bresenham Line
Drawing Algorithm,
Circle Drawing &
Polygon Filling
2
of
39
Contents
In todays lecture well have a look at:
Bresenhams line drawing algorithm
Line drawing algorithm comparisons
Circle drawing algorithms
A simple technique
The mid-point circle algorithm
3
of
39
4
of
39
5
of
39
dupper
dlower
xk+1
m( xk 1) b
6
of
39
d lower
y yk
m( xk 1) b yk
and:
dupper ( yk 1) y
yk 1 m( xk 1) b
We can use these to make a simple decision
about which pixel is closer to the mathematical
line
7
of
39
2b 1
y
x(2 ( xk 1) 2 yk
x
2 y xk
2 y xk
2 x yk
2 x yk
2 y
2b 1)
x(2b 1)
8
of
39
2 y xk 2 x y k c
The sign of the decision parameter pk is the
same as that of dlower dupper
If pk is negative, then we choose the lower
pixel, otherwise we choose the upper pixel
9
of
39
pk
pk
2 y ( xk
xk ) 2 x( yk
yk )
10
of
39
pk
pk
2 y 2 x( yk
yk )
p0
2 y
11
of
39
1.
2.
3.
p0
4.
2 y
pk
pk
2 y
12
of
39
pk
5.
pk
2 y 2 x
13
of
39
Bresenham Example
Lets have a go at this
Lets plot the line from (20, 10) to (30, 18)
First off calculate all of the constants:
x: 10
y: 8
2y: 16
2y - 2x: -4
Calculate the initial decision parameter p0:
p0 = 2y x = 6
14
of
39
18
17
16
15
14
3
4
13
12
11
7
10
8
20
21
22
23 24
25
26
27
28
29
30
pk
(xk+1,yk+1)
15
of
39
Bresenham Exercise
Go through the steps of the Bresenham line
drawing algorithm for a line going from
(21,12) to (29,16)
16
of
39
18
17
16
15
14
3
4
13
12
11
7
10
8
20
21
22
23 24
25
26
27
28
29
30
pk
(xk+1,yk+1)
17
of
39
18
of
39
r2
x2
19
of
39
20 2 0 2
20
y1
202 12
20
y2
202 22
20
y19
20 2 19 2
y20
20 2 20 2
20
of
39
21
of
39
Eight-Way Symmetry
The first thing we can notice to make our circle
drawing algorithm more efficient is that circles
centred at (0, 0) have eight-way symmetry
(-x, y)
(x, y)
(-y, x)
(y, x)
R
2
(-y, -x)
(-x, -y)
(x, -y)
(y, -x)
22
of
39
23
of
39
24
of
39
25
of
39
f circ ( xk 1, yk
( xk 1) 2 ( yk
1 )
2
1 )2 r 2
2
26
of
39
f circ xk
1, yk
2
[( xk 1) 1]
yk
or:
pk
pk
2
k 1
2( xk 1) ( y
2
k
2
1
y ) ( yk
yk ) 1
27
of
39
1 )
2
f circ (1, r
1 )2 r 2
2
1 (r
5
pk
2 xk
pk
2 xk
1 2 yk 1
28
of
39
( x0 , y0 ) (0, r )
p0
pk
pk
2 xk
29
of
39
pk
4.
5.
pk
2 xk
1 2 yk
x
6.
x xc
yc
30
of
39
31
of
39
10
9
8
6
5
3
2
0
0
3 4
9 10
pk
(xk+1,yk+1)
2xk+1
2yk+1
32
of
39
33
of
39
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
k
0
1
2
3
4
5
6
7
8
9
10
11
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
12
pk
(xk+1,yk+1)
2xk+1
2yk+1
34
of
39
35
of
39
Filling Polygons
So we can figure out how to draw lines and
circles
How do we go about drawing polygons?
We use an incremental algorithm known as
the scan-line algorithm
36
of
39
Scan Line
10
12
14
16
37
of
39
38
of
39
39
of
39
40
of
39
Anti-Aliasing
41
of
39
42
of
39
3
1
43
of
39
3
1
44
of
39
M
5
3
1
45
of
39
Blank Grid
46
of
39
Blank Grid
47
of
39
Blank Grid
10
9
8
7
6
5
4
3
2
1
0
0
9 10
48
of
39
Blank Grid