9
Computer Computer Graphics Graphics UNIT-1 UNIT-1 Bresenham’s Circle Bresenham’s Circle Algorithm Algorithm By www.nskinfo.com & www.nsksofttech. By www.nskinfo.com & www.nsksofttech.

Computer Graphics UNIT-1 Bresenhams Circle Algorithm By &

Embed Size (px)

Citation preview

Page 1: Computer Graphics UNIT-1 Bresenhams Circle Algorithm By  &

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

Page 2: Computer Graphics UNIT-1 Bresenhams Circle Algorithm By  &

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

Page 3: Computer Graphics UNIT-1 Bresenhams Circle Algorithm By  &

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

Page 4: Computer Graphics UNIT-1 Bresenhams Circle Algorithm By  &

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)

Page 5: Computer Graphics UNIT-1 Bresenhams Circle Algorithm By  &

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

Page 6: Computer Graphics UNIT-1 Bresenhams Circle Algorithm By  &

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)

Page 7: Computer Graphics UNIT-1 Bresenhams Circle Algorithm By  &

7

ExercisesExercises

Draw the circle with r = 12 using the Bresenham algorithm.

Draw the circle with r = 14 and center at (15, 10).

Page 8: Computer Graphics UNIT-1 Bresenhams Circle Algorithm By  &

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

Page 9: Computer Graphics UNIT-1 Bresenhams Circle Algorithm By  &

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