Unit-1.2.4 Mid-Point Circle Drawing
Unit-1.2.4 Mid-Point Circle Drawing
• Circle Equation:
• (x xc )2 ( y y c )2 r2
y yc r 2 (x c x)2
2
Problem (in above method)
• Computational complexity
• Spacing:
– Non-uniform spacing of plotted pixels
3
Adjustments (To fix problems)
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
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
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:
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:
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
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
19
References
1. Computer Graphics, 2nd Ed., Hearn & Baker –PHI, New Delhi.
20
THANK YOU
21