Chapter 3.3
Chapter 3.3
Chapter – 8 (part - B)
Graphics Pipeline
Mohammad Imrul Jubair
Outline
• Bresenham’s Circle Drawing Algorithm
2
Assumptions
Given,
Radius R circumference
3
Assumptions
The first pixel of the circumference is plotted on (0, R)
Given,
Radius R
(0, R)
(0,0)
4
Observation
The first pixel of the circumference is plotted on (0, R)
Then the plotting of next pixels starts clock-wise….
4 1
(0,0)
8
5
6 7
5
Observation
6
Observation
(0,R)
(R,0)
7
Observation
(0,R) (X,Y)
(R,0)
8
Observation
(0,R) (X,Y)
X=Y
45o
(R,0)
9
Observation
(0,R) (X,Y)
X=Y
45o (Y,X)
(R,0)
10
Observation
45o (Y,X)
(R,0)
11
Observation
(X,Y)
(-X,Y)
So, if we can obtain (X,Y) in 2nd
octant, we can calculate the
(Y,X) points-
• 7th Octant : (X,-Y)
• 6th Octant : (-X, -Y)
• 3rd Octant : (-X, Y)
(X,-Y)
(-X,-Y)
12
Observation
(X,Y)
(-X,Y)
So, if we can obtain (X,Y) in 2nd
octant, we can simply swap X
(Y,X) and Y to get the points-
(-Y,X) • 1 st Octant : (Y, X)
• 8th Octant : (Y, -X)
• 5th Octant : (-Y, -X)
(-Y,-X) (Y,-X) • 4th Octant : (-Y, X)
(X,-Y)
(-X,-Y)
13
Drawing in all the octants
14
Bresenham’s Circle Drawing Algorithm: How it works
(0, R) C
15
Bresenham’s Circle Drawing Algorithm: How it works
SE
16
Bresenham’s Circle Drawing Algorithm: How it works
SE
17
Bresenham’s Circle Drawing Algorithm: How it works
SE
18
Bresenham’s Circle Drawing Algorithm: How it works
SE
19
Bresenham’s Circle Drawing Algorithm: How it works
(0, R)
Next pixel is chosen
(from E or SE) to build
the line successively
E
SE
20
Bresenham’s Circle Drawing Algorithm: How it works
(0, R)
Next pixel is chosen
(from E or SE) to build
the line successively
E
SE
21
Bresenham’s Circle Drawing Algorithm: How it works
(0, R)
As we know that,
In 2nd Octant : X < Y
In 1st Octant : X > Y
22
Equation of Circle and its function representation
(X,Y)
23
Equation of Circle and its function representation
24
Selecting E or SE
C(XP,YP)
25
Selecting E or SE
Selecting E or SE depends
on closeness to the
circumference.
C(XP,YP) E(XP+1,YP)
If E is closer to
circumference,
then E is selected
If SE is closer,
then SE is selected
SE(XP+1,YP-1)
26
Selecting E or SE using Mid Point Criteria
If midpoint M is outside
the circle, SE is closer to
the circumference,
So, SE is selected
If midpoint M is inside
the circle, E is closer to
the circumference,
So, E is selected
27
Selecting E or SE using Mid Point Criteria
We know,
Lets put the mid point M’s coordinate in function F(X,Y)
F(M) = F(XP + 1, YP – 0.5) = (XP + 1)2 + (YP – 0.5)2 – R2
SE(XP+1,YP-1)
28
Selecting E or SE using Mid Point Criteria
29
Bresenham’s Mid Point Criteria : Successive Updating (for selecting E)
d1 =F(M1)
= F(XP+1, YP- 0.5)
= (XP+1)2 + (YP- 0.5)2 - R2
C(XP,YP) E
M1
SE
30
Bresenham’s Mid Point Criteria : Successive Updating (for selecting E)
d1 =F(M1)
= F(XP+1, YP- 0.5)
= (XP+1)2 + (YP- 0.5)2 - R2
C(XP,YP) E
If d1 < 0, E(XP=XP+1, YP)
M1
SE
31
Bresenham’s Mid Point Criteria : Successive Updating (for selecting E)
d1 =F(M1)
= F(XP+1, YP- 0.5)
= (XP+1)2 + (YP- 0.5)2 - R2
C E
If d1 < 0, E(XP=XP+1, YP)
d2 = F(M2)
M2
= F(XP+2, YP-0.5)
= (XP+2)2 + (YP- 0.5)2 - R2
= XP2+ 4XP + 4 + (Y P- 0.5)2 -R2
SE = XP2+ 2XP + 1 + (YP - 0.5)2 - R2 + 2XP + 3
= d1 + (2XP+3)
32
Bresenham’s Mid Point Criteria : Successive Updating (for selecting E)
d1 =F(M1)
= F(XP+1, YP- 0.5)
= (XP+1)2 + (YP- 0.5)2 - R2
C E
If d1 < 0, E(XP=XP+1, YP)
d2 = F(M2)
M2
= F(XP+2, YP-0.5)
= (XP+2)2 + (YP- 0.5)2 - R2
= XP2+ 4XP + 4 + (Y P- 0.5)2 -R2
SE = XP2+ 2XP + 1 + (YP - 0.5)2 - R2 + 2XP + 3
= d1 + (2XP+3)
33
Bresenham’s Mid Point Criteria : Successive Updating (for selecting E)
34
Bresenham’s Mid Point Criteria : Successive Updating (for selecting SE)
d1 =F(M1)
= F(XP+1, YP- 0.5)
= (XP+1)2 + (YP- 0.5)2 - R2
C(XP,YP) E
M1
SE
35
Bresenham’s Mid Point Criteria : Successive Updating (for selecting SE)
d1 =F(M1)
= F(XP+1, YP- 0.5)
= (XP+1)2 + (YP- 0.5)2 - R2
M1
SE
36
Bresenham’s Mid Point Criteria : Successive Updating (for selecting SE)
d1 =F(M1)
= F(XP+1, YP- 0.5)
= (XP+1)2 + (YP- 0.5)2 - R2
If d1 >= 0, SE(XP=XP+1, YP-1)
d2 = F(M2)
C E
…. DIY….
M2
= d1 + (2XP- 2YP+5)
SE
37
Bresenham’s Mid Point Criteria : Successive Updating (for selecting SE)
38
Bresenham’s Mid Point Criteria : Successive Updating (summary)
39
Initialization
SE(XP+1, YP-1)
40
Initialization
41
Initialization
R=2
d = 1.25 – R = – 0.75
R=2
d = 1 – R = –1
42
Summary
So, finally…..
dINIT = 1 – R
Where,
ΔE = 2XP + 3
ΔSE = 2XP – 2YP + 5
43
Algorithm
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9
8
7
6
5
4
46
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7
6
5
4
47
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7
6
5
4
K 1
2x 0
2y 20
h
(x,y)
48
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7
6
5
4
K 1
2x 0
2y 20
h
(x,y) E(1,10)
h <= 0,E
49
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7 h = h+ΔE=h+2x+3
6 =-9+0+3
=-6
5
4
K 1
2x 0
2y 20
h -6
(x,y) E(1,10)
50
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7
6
5
4
K 1 2
2x 0 2
2y 20 20
h -6
(x,y) E(1,10)
51
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7
6
5
4
K 1 2
2x 0 2
2y 20 20
h -6
(x,y) E(1,10) E(2,1 0)
h <= 0,E
52
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7 h = h+ΔE=h+2x+3
6 =-6+2+3
=-1
5
4
K 1 2
2x 0 2
2y 20 20
h -6 -1
(x,y) E(1,10) E(2,1 0)
53
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7
6
5
4
K 1 2 3
2x 0 2 4
2y 20 20 20
h -6 -1
(x,y) E(1,10) E(2,1 0)
54
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7
6
5
4
K 1 2 3
2x 0 2 4
2y 20 20 20
h -6 -1
(x,y) E(1,10) E(2,1 0) E(3,1 0)
h <= 0,E
55
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7 h = h+ΔE=h+2x+3
6 =-1+4+3
=6
5
4
K 1 2 3
2x 0 2 4
2y 20 20 20
h -6 -1 6
(x,y) E(1,10) E(2,1 0) E(3,1 0)
56
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7
6
5
4
K 1 2 3 4
2x 0 2 4 6
2y 20 20 20 20
h -6 -1 6
(x,y) E(1,10) E(2,1 0) E(3,1 0) S(4,9)
h > 0,SE
57
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7 h = h+ΔSE=h+2x-2y+5
6 =6+6-20+5
=-3
5
4
K 1 2 3 4
2x 0 2 4 6
2y 20 20 20 20
h -6 -1 6 -3
(x,y) E(1,10) E(2,1 0) E(3,1 0) S(4,9)
58
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7
6
5
4
K 1 2 3 4 5 6 7
2x 0 2 4 6 8 10 12
2y 20 20 20 20 18 18 16
h -6 -1 6 -3 8 5 6
(x, y) E(1,10) E(2,10) E(3,10) S(4,9) E(5,9) S(6,8) S(7,7)
59
Example
0 1 2 3 4 5 6 7 Given:
10 Radius , R = 10
9 (x,y)=(0,10)
8 h = 1 –R= -9
7
6
5
4
Untill y >x
K 1 2 3 4 5 6 7
2x 0 2 4 6 8 10 12
2y 20 20 20 20 18 18 16
h -6 -1 6 -3 8 5 6
(x, y) E(1,10) E(2,10) E(3,10) S(4,9) E(5,9) S(6,8) S(7,7)
60
Practice Problem
• Perform the midpoint algorithm to draw a circle’s portion at 7th octant
which has center at (2,-3) and a radius of 7 pixels. Show each
iterations and plot the points.
61