Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
108 views

Circle Drawing Algorithms

The document discusses several algorithms for drawing circles: 1) Direct and polar coordinate approaches which calculate points directly from the circle equation. 2) Bresenham's and midpoint circle algorithms which use optimization to incrementally determine points along the circle boundary in a faster, more efficient manner than direct calculation. The midpoint circle algorithm works by evaluating the discrete circle equation at integer coordinates and their midpoints to determine if the current point is on, inside, or outside the circle. Bresenham's algorithm compares the error terms of two candidate points to select the one closer to the true circle. Pseudocode is provided for both algorithms.

Uploaded by

niharranjanroy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views

Circle Drawing Algorithms

The document discusses several algorithms for drawing circles: 1) Direct and polar coordinate approaches which calculate points directly from the circle equation. 2) Bresenham's and midpoint circle algorithms which use optimization to incrementally determine points along the circle boundary in a faster, more efficient manner than direct calculation. The midpoint circle algorithm works by evaluating the discrete circle equation at integer coordinates and their midpoints to determine if the current point is on, inside, or outside the circle. Bresenham's algorithm compares the error terms of two candidate points to select the one closer to the true circle. Pseudocode is provided for both algorithms.

Uploaded by

niharranjanroy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Circle Drawing Techniques

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

Circle Generating Algorithms

Direct
Polar coordinate based
Bresenhams circle drawing algo
Mid-point circle drawing algo

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

Direct Circle Algorithm


Cartesian Coordinates
Circle equation:
( x - xc )2 + ( y - yc )2 = r2

r
(xc,,yc)

Step along x axis from xc - r to xc + r


and calculate
y = yc r2 - ( x - xc )2

Xc - r

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

Xc + r

Polar Coordinates
Polar coordinate equation
x = xc + r cos
y = yc + r sin
step through values of
from 0 to 2

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

r sin

r cos

Optimisation and speed-up


Symmetry of a
circle can be used

(-x,y)

(x,y)

Calculations of
(-y,x)
point Coordinates
only for a first one- (-y,-x)
eighth of a circle

(y,x)

(y,-x)
(-x,-y)

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

(x,-y)
5

Mid-Point Circle Drawing Algorithm


Yi

D=F(x,y)=x2+y2-r2

Yi-1

D
=0
<0
>0

Location
On circle
Inside circle
Outside circle

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

Yi-1/2

Xi Xi+1

Mid-Point Circle Drawing Algorithm


Yi

D=f(x,y)=x2+y2-r2

Yi-1

Yi-1/2

Di=f(Xi+1,Yi-1/2)=(Xi+1)2+(Yi-1/2)2-r2
Xi Xi+1
1

Di+1=(Xi+1+1)2+(Yi+1-1/2)2-r2

Now 2 - 1 gives
Di+1=Di+2Xi-(Y2i+1-Y2i)+(Yi+1-Yi)+3
Nihar Ranjan Roy,
https://sites.google.com/site/niharranjanroy/

Mid-Point Circle Drawing Algorithm.


Yi

Di+1=Di+2Xi-(Y2i+1-Y2i)+(Yi+1-Yi)+3
If Di<0 then
Yi+1=Yi
Di+1=Di+2Xi+3

Yi-1

Yi-1/2

Xi Xi+1

Else
Yi+1=Yi-1
Di+1=Di+2(Xi-Yi)+5

X++;

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

Mid-Point Circle Drawing Algorithm


Now the initial condition
D0=?
Put Xi=0 and Yi=r in eq. 1

(0,r)

D0= 5/4 r 1 - r

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

Mid-Point Circle Drawing Algorithm.


void midPointCircle(int xc, int yc, int rad, int
col)
//center of circle,radius,
{ int x=0, y=rad, d=1-rad;
putpixel(xc+x, yc+y, col);
while(y>x)
{
if(d<0)
d+=2*x+3;
else
{d+=2*(y-x)+5; y--;}
x++;
putpixel(xc+x, yc+y, col);
}

}
Nihar Ranjan Roy,
https://sites.google.com/site/niharranjanroy/

10

PROBLEM
Find all the points in the first quadrant for
radius=10

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

11

(x0,y0)=(0,10)
d0=1-r=1-10=-9
Current

next

0,10

d<0
d=d+2x+3=-9+2*0+3=-6

(1,10)

(1,10)

d<0
d=d+2x+3=-6+2*1+3=-1

(2,10)

(2,10)

d<0
d=d+2x+3=-1+2*2+3=6

(3,10)

(3,10)

d>0
d=d+2(x-y)+5=6-14+5=-3

(4,9)

(4,9)

d<0
d=d+2x+3=-3+2*4+3=8

(5,9)

(5,9)

d>0
d=d+2(x-y)+5=8-8+5=5

(6,8)

(6,8)

d>0
d=d+2(x-y)+5=5-4+5=5

(7,7)

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

12

Bresenhams Circle Drawing Technique


D(T)=(xi+1)2+yi2-r2
D(S)=(xi+1)2+(yi-1)2-r2

Yi
Yi-1

T
S

D(T)=always positive
D(S)=always negative

Xi Xi+1

di=D(T)+D(S)

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

13

Bresenhams Circle Drawing Technique


di=D(T)+D(S)

di
=0
<0
>0

Selection
Choose any
Choose T
Choose S

Yi
Yi-1

T
S

Xi Xi+1

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanro

14

Bresenhams Circle Drawing Technique


di=D(T)+D(S)

di=2(xi+1)2+yi2+(yi-1)2-2r2

Yi
Yi-1

T
S

di+1=2(xi+1+1)2+yi+12+(yi+1-1)2-2r2 2
Now 2 1 gives us
di+1=di+4xi+2(y2i+1-y2i)-2(yi+1-yi)+6

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

Xi Xi+1

15

Bresenhams Circle Drawing Technique


di+1=di+4xi+2(y2i+1-y2i)-2(yi+1-yi)+6 YYi
i-1
If di<0 then T is chosen so yi+1=yi

T
S

di+1=di+4xi+6
r

Else
S is chosen yi+1=yi-1
di+1=di+4(xi-yi)+10
d0=3-2r by subs xi=0 and yi=r in eq. 1

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

Xi Xi+1

16

Bresenhams circle algorithm


1. Input radius r
2. Plot a point at (0, r) set x=0 and y=r
3. Calculate the initial decision parameter as d0 = 3-2 r
4. while (x<y)
5. {if (d<0)
6.
d=d+4x+6;
7. else
8.
{d=d+4(x-y)+10;
9.
y--;}
10.x++;
11.}
12.
Nihar Ranjan Roy,
https://sites.google.com/site/niharranjanroy/

17

PROBLEM
Find all the points in the first octant for
radius=10 using Bresenhams circle drawing
technique.

Nihar Ranjan Roy,


https://sites.google.com/site/niharranjanroy/

18

You might also like