Transcript
Page 1: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

1

Circle Drawing Algorithms

Pictures snagged from http://accad.osu.edu/~waynec/history/

Page 2: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

2

Drawing Circles and Arcs

Similar to line drawing In that you have to determine what pixels to

activate But non-linear

Simple equation implementation Optimized

Page 3: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

3

Cartesian form ofCircle Equations

(xc, yc)

2 2 2

22

c c

c c

x x y y r

or

y y r x x

r

Not a very good method. Why?

Page 4: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

4

Be the algorithm!

Page 5: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

5

What does it do?

0

1

2

3

4

5

6

7

8

0 1 2 3 4 5 6 7 8 9 10 11

Page 6: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

6

Polar Coordinate Form

(x, y)cos

sinc

c

x x r

y y r

r

Simple method: plot directly from parametric equations

θ

1

1

s r

s

r

Page 7: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

7

Trig functions are expensive

( 1) 2 1(2 1)!

0

( 1) 2(2 )!

0

sin

cos

n

n

nn

n

nn

n

Plots of first 1, 3, 5, 7, 9, 11, and 13 terms in the Taylor’s series for sin

Page 8: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

8

Polygon Approximation

(xi, yi)

Calculate polygon vertices from polar

equation; connect with line algorithm

Page 9: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

9

The Bresenham Algorithms

Bresenham, J. E. Algorithm for computer control of a digital plotter, IBM Systems Journal, 4(1), 1965, pp. 25-30.

Bresenham, J. E. A linear algorithm for incremental digital display of circular arcs. Communications of the ACM, 20(2), 1977, pp. 100-106.

Page 10: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

10

Bresenham’s Midpoint Circle Algorithm

0, if (x,y) inside circle

, 0, if (x,y) on circle

0, if (x,y) outside circlecirclef x y

2 2 2,circlef x y x y r

0<|m|<1 in this region

Page 11: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

11

The Circle Decision Parameter

2

2 2

2 2 2

11,

2

11

2

12 1

4

k circle k k

k k

k k k k

p f x y

x y r

x x y y r

Calculate fcircle for point midway between candidate

pixels

xk

yk

Plot 1,k kx yIf pk < 0:

If pk >= 0: Plot 1, 1k kx y

Page 12: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

12

Calculating pk+1

1 1

22 2

1

2

1

2 21 1

11,

2

11

2

14 4

4

1

k circle k

k

k k k k

k

k

p f y

y r

x

x

x y

x

y r

Page 13: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

13

Recurrence Relation for pk

2 21 1 1

2 21 1 1

(2 2) 1

2 1

k k k k k k k

k k k k k k

p p x y y y y

p x y y y y

2 2 212 1

4k k k k kp x x y y r

2 2 21 1 1

14 4

4k k k k kp x x y y r

Page 14: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

14

One Last Term …

2 21 1 ?k k k ky y y y

If yk+1 = yk, then:

2 2 0k k k ky y y y

If yk+1 = yk-1, then:

2 2

2 2

1 1

2 1 1

2 2 2 1

k k k k

k k k

k k

y y y y

y y y

y y

Page 15: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

15

Initial Values 0 0

0

, 0,

10 1,

2circle

x y r

p f r

22

2 2

11

2

11

45

14

r r

r r r

r r

Page 16: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

16

Bresenham Midpoint Circle Algorithm Summary

1

Plot 1,

2 1 1

k k

k k k

x y

p p x

At each point:

If pk < 0:

If pk >= 0:

1

Plot 1, 1

2 1 1 2 1

k k

k k k k

x y

p p x y

Page 17: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

17

Circle Example 1

0

1

2

3

4

5

6

7

8

0 1 2 3 4 5 6 7 8 9 10 11

r = 7

Page 18: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

18

Symmetry Optimization

(a, b)

(b, a)

(a, -b)

(b, -a)

(-b, a)

(-b, -a)

(-a, b)

(-a, -b)

Calculate points for

one octant; replicate in other seven

Page 19: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

19

General Ellipse Equation

In general, ellipse described by constant sum of distances from

foci

Difficult to solve equations and plot points

(use parametric polar form?)

Page 20: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

20

Special Case Ellipses

(xc, yc)

22

1c c

x y

x x y y

r r

rx

ry

x x r

y y rc x

c y

cos

sin

Modified midpoint algorithm possible

Page 21: 1 Circle Drawing Algorithms Pictures snagged from waynec/history

CS-321Dr. Mark L. Hornick

21

Drawing Ellipses

General ellipses Polygon approximation Rotation (we’ll defer this until later, when we cover

coordinate transformations) Aligned axes

Constrained (no rotation) Midpoint algorithm


Recommended