Circle Drawing Algorithms
Circle Drawing Algorithms
Direct
Polar coordinate based
Bresenhams circle drawing algo
Mid-point circle drawing algo
r
(xc,,yc)
Xc - r
Xc + r
Polar Coordinates
Polar coordinate equation
x = xc + r cos
y = yc + r sin
step through values of
from 0 to 2
r sin
r cos
(-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)
(x,-y)
5
D=F(x,y)=x2+y2-r2
Yi-1
D
=0
<0
>0
Location
On circle
Inside circle
Outside circle
Yi-1/2
Xi Xi+1
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/
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++;
(0,r)
D0= 5/4 r 1 - r
}
Nihar Ranjan Roy,
https://sites.google.com/site/niharranjanroy/
10
PROBLEM
Find all the points in the first quadrant for
radius=10
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)
12
Yi
Yi-1
T
S
D(T)=always positive
D(S)=always negative
Xi Xi+1
di=D(T)+D(S)
13
di
=0
<0
>0
Selection
Choose any
Choose T
Choose S
Yi
Yi-1
T
S
Xi Xi+1
14
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
Xi Xi+1
15
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
Xi Xi+1
16
17
PROBLEM
Find all the points in the first octant for
radius=10 using Bresenhams circle drawing
technique.
18