Upload
wyatt-mckinnon
View
242
Download
0
Embed Size (px)
Citation preview
Computer GraphicsComputer Graphics
UNIT-1UNIT-1Bresenham’s Circle Bresenham’s Circle
AlgorithmAlgorithm
By www.nskinfo.com & www.nsksofttech.comBy www.nskinfo.com & www.nsksofttech.com
2
Bresenham’s Circle AlgorithmBresenham’s Circle Algorithm
General PrincipleGeneral Principle The circle function:
and
Consider only 45° ≤ ≤ 90°
2 2 2( , )circlef x y x y r
if (x,y) is inside the circle boundary
if (x,y) is on the circle boundary
if (x,y) is outside the circle boundary
0
( , ) 0
0circlef x y
3
Bresenham’s Circle AlgorithmBresenham’s Circle Algorithm
p1 p3
p2
D(si)D(ti)
After point p1, do we choose p2 or p3?
yi
yi - 1
xi xi + 1
r
4
Bresenham’s Circle AlgorithmBresenham’s Circle Algorithm
Define: D(si) = distance of p3 from circle
D(ti) = distance of p2 from circle
i.e. D(si) = (xi + 1)2 + yi2 – r2 [always +ve]
D(ti) = (xi + 1)2 + (yi – 1)2 – r2 [always -ve]
Decision Parameter pi = D(si) + D(ti)
so if pi < 0 then the circle is closer to p3 (point above) if pi ≥ 0 then the circle is closer to p2 (point below)
5
The AlgorithmThe Algorithmx0 = 0y0 = rp0 = [12 + r2 – r2] + [12 + (r-1)2 – r2] = 3 – 2r
if pi < 0 thenyi+1 = yi
pi+1 = pi + 4xi + 6
else if pi ≥ 0 thenyi+1 = yi – 1pi+1 = pi + 4(xi – yi) + 10
Stop when xi ≥ yi and determine symmetry points in the other octants
xi+1 = xi + 1
6
ExampleExample
10 9 8 7 6
5 4 3
2 1 0
0 1 2 3 4 5 6 7 8 9 10
i pi xi, yi
0 -17 (0, 10)
1 -11 (1, 10)
2 -1 (2, 10)
3 13 (3, 10)
4 -5 (4, 9)
5 15 (5, 9)
6 9 (6, 8)
7 (7,7)
r = 10
p0 = 3 – 2r = -17
Initial point (x0, y0) = (0, 10)
7
ExercisesExercises
Draw the circle with r = 12 using the Bresenham algorithm.
Draw the circle with r = 14 and center at (15, 10).
8
Decision ParametersDecision Parameters
Prove that if pi < 0 and yi+1 = yi then
pi+1 = pi + 4xi + 6
Prove that if pi ≥ 0 and yi+1 = yi – 1 then
pi+1 = pi + 4(xi – yi) + 10
9
Advantages of Bresenham circleAdvantages of Bresenham circle
Only involves integer addition, subtraction and multiplication
There is no need for squares, square roots and trigonometric functions