1 Circle Drawing Algorithms Pictures snagged from waynec/history

Post on 13-Jan-2016

214 views 1 download

Transcript of 1 Circle Drawing Algorithms Pictures snagged from waynec/history

1

Circle Drawing Algorithms

Pictures snagged from http://accad.osu.edu/~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

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?

CS-321Dr. Mark L. Hornick

4

Be the algorithm!

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

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

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

CS-321Dr. Mark L. Hornick

8

Polygon Approximation

(xi, yi)

Calculate polygon vertices from polar

equation; connect with line algorithm

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.

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

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

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

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

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

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

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

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

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

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?)

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

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