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

New-Week 3 Circle Generating Algorithm

The document outlines Bresenham's Circle Generating Algorithm, which utilizes the symmetry of circles to efficiently plot points in an octant and employs decision variables to determine pixel placement. It also describes the Mid-Point Circle Algorithm, which similarly uses symmetry and a decision parameter to determine the relationship between a point and the circle. Both algorithms aim to simplify the computation of circle drawing in computer graphics.

Uploaded by

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

New-Week 3 Circle Generating Algorithm

The document outlines Bresenham's Circle Generating Algorithm, which utilizes the symmetry of circles to efficiently plot points in an octant and employs decision variables to determine pixel placement. It also describes the Mid-Point Circle Algorithm, which similarly uses symmetry and a decision parameter to determine the relationship between a point and the circle. Both algorithms aim to simplify the computation of circle drawing in computer graphics.

Uploaded by

Harshit Puri
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Circle Generating Algorithm

Bresenham’s Circle Generating


Algorithm
Scan Converting a Circle

A circle is a symmetric figure. Any circle


generating algorithm can take advantage of
the circle’s symmetry to plot eight points for
each value that the algorithm calculates.
Eight way symmetry is used by reflecting
each calculated point around each 45 º axis.
Bresenham’s Circle Drawing Algorithm
E=East
SE=South East
dold dnew d=Decision Variable
xP, yP (xP, yP)= Current Pixel

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.

If points are generated from 90º to 45º each new point


closest to the true circle can be found by taking
either of two actions:
(1) Move in the x direction one unit or
(2) Move in the x direction 1 unit & -ve y direction 1
unit.
y

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)

• Following expressions can be developed:


D(E) = (xi + 1)2 + yi2 – r2
D(SE) = (xi + 1)2 + (yi – 1)2 – r2
• This function D provides a relative measurement of the
distance from the center of a pixel to the true circle. Since
D(E) is always +ve (E is outside the circle) & D(SE) will
always be –ve (SE is inside the true circle), a decision
variable di can be defined as:
di = D(E) – (-D(SE)) = D(E) + D(SE)
Therefore,
di = 2(xi + 1)2 + yi2 + (yi – 1)2 – 2r2
• When di<0, we have |D(E)|<|D(SE)| and pixel E
is chosen.
• When di≥0, we have |D(E)|≥|D(SE)| and pixel SE
is selected.
Decision variable for next step:
di+1 = 2(xi+1 + 1)2 + yi+12 + (y i+1 – 1)2 – 2r2
Hence,
di+1 – di = 2(xi+1 + 1)2 + yi+12 + (yi+1 – 1)2 -
2(xi + 1)2 - yi2 - (yi – 1)2
Since xi+1 = xi + 1, we have
di+1 = di + 4xi + 2(yi+12 - yi2) – 2(yi+1 – yi) + 6
If E is chosen pixel (meaning that di < 0) then
yi+1 = yi and so di+1 = di + 4xi + 6
If SE is chosen (meaning that di > 0) then yi+1 =
yi –1 and so di+1 = di + 4(xi-yi) + 10
Hence we have
di+1 = di + 4xi + 6 if di < 0
di + 4(xi-yi) + 10 if di > 0
Finally, we set(0,r) to the starting pixel
coordinates and compute d1 from the original
definition of di:
x = 0, y = r
d1= 2(0 + 1)2 + r2 + (r-1)2 – 2r2
d1= 3 – 2r
Algorithm:

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

symmetry to get the rest of


the points
Midpoint Circle Algorithm
Mid point algorithm is very similar to
Bresenham’s approach. It is based on the
following function for testing the spatial
relationship between an arbitrary point(x,y)
and a circle of radius centered at the origin:
< 0 (x,y) inside circle
f(x,y) = x2 + y2 – r2 = 0 (x,y) on the circle
> 0 (x,y) outside circle
T

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:

The following is a description of this midpoint circle algorithm that


generates the pixel coordinates in the 90˚ to 45 ˚ octant:
initialize x = 0, y = r, p = 1-r
while (x <=y)
setpixel(x,y);
if (p < 0)
p = p + 2x + 3
else
p = p + 2(x – y) + 5
y- -
endif
x++
endwhile

You might also like