0% found this document useful (0 votes)
128 views21 pages

Unit-1.2.4 Mid-Point Circle Drawing

This document describes algorithms for generating circles in computer graphics. It discusses issues with directly using the circle equation to plot points and introduces the mid-point circle algorithm as an improvement. The mid-point circle algorithm uses incremental calculations and a decision parameter to determine the pixel closest to the true circle at each step, ensuring evenly spaced points. Pseudocode is provided to illustrate the algorithm, which begins at a starting point, calculates the next point and decision parameter using increments, and repeats until one octant is drawn, applying symmetry to plot the full circle.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views21 pages

Unit-1.2.4 Mid-Point Circle Drawing

This document describes algorithms for generating circles in computer graphics. It discusses issues with directly using the circle equation to plot points and introduces the mid-point circle algorithm as an improvement. The mid-point circle algorithm uses incremental calculations and a decision parameter to determine the pixel closest to the true circle at each step, ensuring evenly spaced points. Pseudocode is provided to illustrate the algorithm, which begins at a starting point, calculates the next point and decision parameter using increments, and repeats until one octant is drawn, applying symmetry to plot the full circle.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

UNIVERSITY INSTITUTE OF COMPUTING

Bachelor of Computer Science


Computer Graphics
20CAT- 312

DISCOVER . LEARN . EMPOWER


1
Circle-Generating Algorithms

• Circle Equation:

• (x  xc )2  ( y  y c )2  r2

Fig. 3.23 Circle with center coordinates


(x,, y,) and radius r. [1]

• Points along circumference could be calculated by


stepping along x-axis

y  yc  r 2  (x c  x)2

2
Problem (in above method)

• Computational complexity
• Spacing:
– Non-uniform spacing of plotted pixels

Fig. 3.24 Positive half of a circle plotted with


circle equation and with (x, y,) = (0.0) [1]

3
Adjustments (To fix problems)

• Spacing problem (2 ways):


– Interchange the role of x and y whenever the absolute value of the slope of
the circle tangent > 1
– Use polar co-ordinate:
x  xc  r
y  yc  r
cos
sin
• Equally spaced points are plotted along the circumference with fixed angular
step size.
• step size chosen for θ depends on the application and display device.
• Computation Problem:
– Use symmetry of circle; i.e calculate for one octant and use symmetry for
others.

4
Bresenham’s Algorithm Could Be
Adapted ??
• Yes
• How ?
– Setting decision parameter for finding the closest
pixel to the circumference
• And what to do For Non-linear equation of
circle ?
– Comparison of squares of the pixel separation
distance avoids square root calculations

5
Circle Drawing
Since the circle is a frequently used component in pictures and
graphs, a procedure for generating either full circles or circular arc
is included in most graphics packages.
Direct Algorithm
The equation for a circle is:
x2 + y2 = r2
Where r is the radius of the circle. So, we can write a direct circle
drawing algorithm by solving the equation for y at unit x intervals
using:
y = (r2 – x2)1/2

6
Direct Algorithm
To draw a circle with radius=20
y(0) = (202 – 02)1/2  20
y(1) = (202 – 12)1/2  20
y(2) = (202 – 22)1/2  20
…..
y(19) = (202 – 192)1/2  6
y(20) = (202 – 202)1/2 = 0

the resulting circle has large gaps


where the slope approaches the
Fig. 3.25 Pixel plotting of circle with
vertical. And the calculations are not centre (0, 0) and radius 20 using direct
very efficient: circle equation [1]

 The square (multiply) operations


 The square root operation
7
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

Fig. 3.26 Symmetry of a circle.


Calculation of a circle point (x, y) in one
octant yields the circle points shown for
the other seven octants [1]

8
Mid-Point Circle Algorithm
As in the raster line algorithm, we sample at unit intervals
and determine the closest pixel position to the specified
circle path at each step.
• For a given radius r and screen center position (xc, yc),
we can first set up our algorithm to calculate pixel
positions around a circle path centered at the coordinate
(0, 0).
• Then each calculated position (x, y) is moved to its
proper screen position by adding xc to x and yc to y.

9
Mid-Point Circle Algorithm

Along the circle section from x = 0 to x = y in the first quadrant,


the slope of the curve varies from 0 to –1. Therefore, we can take
unit steps in the positive x direction over this octant and use a
decision parameter to determine which of the two possible y
positions is closer to the circle path at each step positions in the
other seven octants are then obtained by symmetry.

• To apply the midpoint algorithm, we define a circle function:

fcircle(x, y) = x2 + y2 – r2
10
Mid-Point Circle Algorithm
The relative position of any point (x, y) can be determined by checking the sign
of the on the boundary of the circle function:

< 0 If (x, y) is inside the circle boundary

fcircle(x, y) = 0 If (x, y) is on the circle boundary

>0 If (x, y) is outside the circle boundary

The circle function tests are performed for the midpoints positions between pixels
near the circle path at each sampling step. Thus, circle function is decision
parameter in the midpoint algorithm, and we can set up incremental calculations
for this function as we did in the line algorithm.

11
Mid-Point Circle Algorithm
Assuming we have just plotted point (xk, yk), we next need to determine whether
the pixel at position (xk+1, yk) or the one at position (xk+1, yk–1) is closer to the
circle path. Our decision parameter is The circle function evaluated at the
midpoint between these two pixels:

Fig. 3.26 Midpoint candidate pixel at


sampling position xk + 1 along a circle
path [1]

12
Mid-Point Circle Algorithm
pk = fcircle(xk + 1,yk – 1/2)
= (xk + 1)2 + (yk – 1/2)2 – r2
• If pk < 0, this midpoint is inside the circle and the pixel at yk is closer to the
circle boundary.
• Otherwise the midpoint is outside or on the circle boundary, and we select the
pixel at yk–1.
 Successive decision parameters are obtained using incremental calculations.
We obtain a recursive expression for the next decision parameter by evaluating
the circle function at sampling position xk+1 + 1 = xk + 2
pk+1 = fcircle(xk+1 + 1,yk+1 – 1/2)
= ((xk + 1) + 1)2 + (yk – 1/2)2 – r2

13
Mid-Point Circle Algorithm

pk+1 = pk + 2(xk+1) + (yk +12 – yk 2 ) – (yk +1 – yk) + 1

Where yk+1 is either yk or yk-1 depending on the sign of pk


Increments for obtaining pk+1 are either 2xk+1 + 1 (if pk is negative) or 2xk+1 + 1 –
2yk+1.
Evaluation of the terms 2xk+1 and 2yk+1 can also be done incrementally as:
2xk+1 = 2xk+1 + 2
2yk+1 = 2yk+1 – 2
At the starting position (0, r), these two terms have the values 0 and 2r,
respectively. Each successive value is obtained by adding 2 to the previous
value of 2x and subtracting 2 from the previous value of 2y.
14
Mid-Point Circle Algorithm
The initial value of the decision parameter is obtained by
evaluating the circle function at the start position
(x0, y0) = (0, r)
P0 = fcircle(1, r – 1/2)=1 + (r – 1/2)2 – r2
or P0 = 5/4 – r
If the radius r is specified as an integer, we can simply round P0 to
P0 = 1 – r (for integer r)
Since all increments are integers.

15
Mid-Point Circle Algorithm

PSEDUO CODE
1. Input radius r and circle centre (xc, yc), and obtain the first point on the
circumference of a circle centred on the origin as:
(x0, y0) = (0, r)
2. Calculate the initial value of the decision parameter as:
P0 = 5/4 – r
3. At each position xk Starting with k=0, perform the following test.
If pk < 0, the next point along the circle centred on (0, 0) is (xk+1 , yk) and
pk+1 = pk + 2xk+1 + 1
Otherwise the next point along the circle is (xk+1 , yk– 1) and
pk+1 = pk + 2xk +1 +1 – 2yk +1
where 2xk+1 = 2xk+1 + 2 and 2yk+1= 2yk+1 – 2
16
Mid-Point Circle Algorithm
PSEDUO CODE cont.
4. Determine symmetry points in the other seven octants
5. Move each calculated pixel position (x, y) onto the circular
path centred at (xc, yc) and plot the coordinate values:
x = x+ xc y = y+ yc
6. Repeat steps 3 to 5 until x >= y

17
Mid-Point Circle Algorithm
Mid-Point Circle Algorithm Example
Given a circle radius=10, we demonstrate the midpoint circle algorithm by
determining positions along the circle octant in the first quadrant from x = 0 to x
= y. the initial value of the decision parameter is P0 = 1 – r = – 9

For the circle centred on the origin, the initial point is (x0, y0) = (0, 10), and

the initial increment term for calculating the decision parameters are
2x0 = 0 and 2y0= 20

Successive decision parameters values and positions along the circle path are
calculated using midpoint algorithm as:

18
Mid-Point Circle Algorithm
k Pk xk+1 , yk– 1 2xk+1 2yk+1
0 -9 (1, 10) 2 20
1 -6 (2, 10) 4 20
2 -1 (3, 10) 6 20
3 6 (4, 9) 8 18
4 -3 (5, 9) 10 18
5 8 (6, 8) 12 16
6 5 (7, 7) 14 14

Fig. 3.10 Pixel calculation for circle with


radius r = 10 centered on the origon [1] Fig. 3.27 Selected pixel positions (solid
circles) along a circle path with radius r =
10 centered on the origin, using the
A plot of the generated pixel positions in the first midpoint circle algorithm. Open circles
show the symmetry positions in the first
quadrant is shown in the figure 3.27 quadrant. [1]

19
References

1. Computer Graphics, 2nd Ed., Hearn & Baker –PHI, New Delhi.

2. Graphics Programming with C By Yashwant Kanetkar, BPB

Publications, New Delhi.

3. Computer Graphics, Schaum’s Outline Series, MGH Publications.

20
THANK YOU

21

You might also like