New-Week 3 Circle Generating Algorithm
New-Week 3 Circle Generating Algorithm
SE
Scan Convert a Circle using trigonometric
method:-
This second method of defining a circle uses
functions : x = r cos θ, y = r sin θ
y
P(r cos θ,r sin θ)
r sin θ
θ
x
r cos θ
θ = current angle, r = circle radius
By this method θ is stepped from θ to π /4
& each value of x & y is calculated.
Computation of values of sin θ & cos θ are
very time consuming
Bresenham’s Circle Algorithm
Working: If the eight-way symmetry of a circle is used
to generate a circle, points will have to be
generated through 45º angle. And, if points are
generated from 90º to 45º, moves will be made
only in the +x and –y directions.
E (xi+1,yi)
yi
(xi+1,yi-1)
yi -1
SE
xi xi + 1 x
• Assume that (xi, yi) are the coordinates of the last scan-
converted pixel upon entering step i.
• Coordinates of
E are (xi +1, yi)
SE are (xi +1, yi – 1)
For generating all the pixel coordinates in the 90º to 45º octant that are needed
when scan-converting a circle of radius r.
(i) Initialize x = 0, y = r, d = 3-2r
(ii) while (x<= y)
setpixel(x,y)
if (d < 0) Given x=0, y=r=5. Assume center is at (0,0)
d = d + 4x + 6 x y setpixel(x,y) d
else 0 r=5 (0,5) 3-2r=-7
d = d + 4(x - y) + 10 1 5 (1,5) -7+0+6=-1
y = y-1 2 5 (2,5) -1+4+6=+9
endif
3 4 (3,4) 9+4(2-5)+10=+7
x =x+1
4 3 (4,3) 7+4(3-4)+10=+13
endwhile
x>y Stop
Eight-Way Symmetry
• The first thing we can notice to make our circle
drawing algorithm more efficient is that circles
centred at (0, 0) have eight-way symmetry.
y
-y,x y,x
-x,y x,y
-x,-y x,-y
y,-x
-y,-x
Mid Point Circle Drawing
Algorithm
Mid-Point Circle Algorithm
• Similarly to the case with
lines, there is an incremental
algorithm for drawing circles –
the mid-point circle algorithm
• In the mid-point circle
algorithm we use eight-way
symmetry so we calculate the
The mid-point circle
points for the second octant algorithm was developed
of a circle, and then use by Jack Bresenham
S
• Now consider the coordinates of the point
halfway between pixel T & S (xi + 1, yi – ½)
This is called the midpoint and we use it to
define a decision parameter:
pi = f( xi +1, yi – ½)
= (xi + 1)2 + (yi – ½)2 – r2
• If pi is –ve , the midpoint is inside the circle,
then we choose the y pixel.
• If pi is +ve, the midpoint is outside the circle,
& we choose the y-1 pixel.
• Similarly, the decision parameter for the next
step is:
pi+1 = (xi+1 + 1)2 + (yi+1 – ½)2 – r2
• Since x i+1 = xi + 1
pi+1 - pi = [(xi + 1)+ 1]2 – (xi + 1)2
+ (y i+1 – ½)2 – (yi – ½)2
• Hence
pi+1 = pi + 2(xi + 1) + 1 + (y i+12 – yi2)
– (y i+1 – yi)
If pixel T is chosen (meaning pi < 0), we have
yi+1 = yi.
If pixel S is chosen (meaning pi > 0), we have
yi+1 = yi – 1. Thus,
pi+1= pi + 2(xi + 1) +1 if pi<0
pi + 2(xi + 1) +1 – 2(yi – 1) if pi>0
In terms of (xi, yi), we have
pi+1= pi + 2xi + 3 if pi<0
pi + 2(xi - yi ) + 5 if pi>0
• Finally, we compute the initial value for the
decision parameter using the original
definition of pi and (0,r):
pi = (0 + 1)2 + (r – ½)2 – r2 = 5/4 – r
• One can see that this is not really integer
computation. However, when r is an integer
we can simply set p1= 1 – r.
• The error of being ¼ less than the precise
value does not prevent p1 from getting the
appropriate sign.
• It does not affect the rest of the scan
conversion process, because the decision
variable is only updated with integer
increment in subsequent steps.
Mid Point Circle Algorithm: