Professional Documents
Culture Documents
Bresenham Line
Drawing Algorithm,
Circle Drawing &
Polygon Filling
By:Kanwarjeet Singh
2
of
50
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
50
DDA
Digital differential analyser
Y=mx+c
For m<1
y=mx
For m>1
x=y/m
4
of
50
Question
A line has two end points at (10,10) and
(20,30). Plot the intermediate points using
DDA algorithm.
5
of
50
6
of
50
7
of
50
dupper
dlower
xk+1
y m( xk 1) b
8
of
50
d lower y yk
m( xk 1) b yk
and:
d upper ( 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
9
of
50
y
d upper ) x(2 ( xk 1) 2 yk 2b 1)
x
2y xk 2x yk 2y x(2b 1)
2y xk 2x yk c
10
of
50
2y xk 2x yk 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
11
of
50
pk 1 pk 2y ( xk 1 xk ) 2x( yk 1 yk )
12
of
50
pk 1 pk 2y 2x( yk 1 yk )
where yk+1 - yk is either 0 or 1 depending on
the sign of pk
The first decision parameter p0 is evaluated
at (x0, y0) is given as:
p0 2y x
13
of
50
1.
2.
3.
p0 2y x
4.
pk 1 pk 2y
14
of
50
pk 1 pk 2y 2x
5.
15
of
50
Adjustment
For m>1, we will find whether we will
increment x while incrementing y each time.
After solving, the equation for decision
parameter pk will be very similar, just the x
and y in the equation will get interchanged.
16
of
50
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
17
of
50
18
17
16
1
2
15
14
13
12
11
10
8
20
21
22
23 24
25
26
27
28
29
30
pk
(xk+1,yk+1)
18
of
50
Bresenham Exercise
Go through the steps of the Bresenham line
drawing algorithm for a line going from
(21,12) to (29,16)
19
of
50
18
17
16
15
2
3
14
13
12
11
10
8
20
21
22
23 24
25
26
27
28
29
30
pk
(xk+1,yk+1)
20
of
50
21
of
50
22
of
50
y19 20 2 19 2 6
y20 20 2 20 2 0
23
of
50
24
of
50
Polar coordinates
X=r*cos+xc
Y=r*sin+yc
0360
Or
0 6.28(2*)
Problem:
Deciding the increment in
Cos, sin calculations
25
of
50
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)
26
of
50
27
of
50
3
1
28
of
50
3
1
29
of
50
M
5
3
1
30
of
50
(xk, yk)
(xk+1, yk)
(xk+1, yk-1)
31
of
50
32
of
50
33
of
50
pk 1 f circ xk 1 1, yk 1 1
or:
[( xk 1) 1] yk 1
2
pk 1 y
pk is
2either
( xk 1)y (or
y y -1y depending
) ( yk 1 yk on
) 1
where
k+1
k
k
the sign of pk
2
k 1
2
k
34
of
50
35
of
50
( x0 , y0 ) (0, r )
p0 5 r
4
pk 1 pk 2 xk 1 1
36
of
50
pk 1 pk 2 xk 1 1 2 yk 1
4.
5.
x x xc
6.
y y yc
37
of
50
38
of
50
10
9
8
5
4
2
1
6
0
3 4
9 10
pk
(xk+1,yk+1)
2xk+1
2yk+1
39
of
50
40
of
50
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
41
of
50
42
of
50
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
43
of
50
Scan Line
10
12
14
16
44
of
50
45
of
50
46
of
50
47
of
50
Blank Grid
48
of
50
Blank Grid
49
of
50
Blank Grid
10
9
8
7
6
5
4
3
2
1
0
0
3 4
9 10
50
of
50
Blank Grid