0% found this document useful (0 votes)
165 views

Midpoint Circle Drawing Algorithm

Midpoint Circle Drawing Algorithm

Uploaded by

Moturu Karthik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
165 views

Midpoint Circle Drawing Algorithm

Midpoint Circle Drawing Algorithm

Uploaded by

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

A Circle Drawing Algorithm

Circle generating algorithms


o Direct method

o Bresenham’s algorithm

o Midpoint Circle Algorithm


Eight-Way Symmetry

The firstthing we can notice to make our circle drawing algorithm more
efficient isthat circles centred at (0,0)have eight-waysymmetry

9
Circle exhibit octant symmetry.
A circle is symmetric about its octants.

If we know a point on any one of the


octants, the remaining 7 symmetric
points can be plotted by interchanging
the magnitudes of x and y and also
signs.

It is enough that we compute points on


one of the octants. The remaining points
can be easily plotted without any
computations.
Midpoint Circle Algorithm
Assuming the circle is centered at origin
and has a radius r units, the algorithm
can start with a known point (0, r) and
proceed to compute points till the end of
the octant is reached.

We need to find out the stopping


condition for the algorithm. Needs to
find the end of the octant.
Simplest way is to observe the 45 degree
line , that is the axis which satisfies the
equation, x=y, that means all points that
lie on that axis are like, (2,2) (3,3) and
so on.
This axis divides the first positive quadrant into
two zones or two octants.
All points on the upper side of the axis satisfy the
relation x<y, while all the points on the lower
side of the axis satisfy the relation x>y.

stopping condition : check the relation between x


and y, i.e., as long as x<=y do the computation,
and stop when the relation x<=y is not satisfied
by the points.
Observe that in the chosen octant, while we proceed to compute points on
the circle boundary, the slope of the circle changes from 0 (positive) to -1
(negative).
This axis divides the first positive quadrant into
two zones or two octants.
All points on the upper side of the axis satisfy the
relation x<y, while all the points on the lower
side of the axis satisfy the relation x>y.

stopping condition : check the relation between x


and y, i.e., as long as x<=y do the computation,
and stop when the relation x<=y is not satisfied
by the points.
Observe that in the chosen octant, while we proceed to compute points on
the circle boundary, the slope of the circle changes from 0 (positive) to -1
(negative).
Midpoint Circle Algorithm
• While x increases, y decreases. Because the circle has slope
that is almost flat, we can sample the circle along x-axis at
unit steps and compute the corresponding y-values.

•Start at (0,r)
•End at (x,y) such that x>=y i.e. whenever x becomes >=y we
can stop the algorithm.
•Because the shape of the circle in this region is more flat, we
can sample it along X-axis at unit intervals, and compute the
corresponding y-values
Principle behind Midpoint Circle Algorithm
•Equation of circle with centre at origin, and having a radius of r
units is given by 𝑥 2 + 𝑦 2 = 𝑟 2

•𝑥 2 + 𝑦 2 − 𝑟 2 = 0 Point (x,y) lies on the circle boundary


•𝑥 2 + 𝑦 2 − 𝑟 2 < 0 Point (x,y) inside the circle boundary
•𝑥 2 + 𝑦 2 − 𝑟 2 > 0 Point (x,y) lies outside the circle boundary

• Decision parameter 𝑝𝑘 = 𝑥 2 + 𝑦 2 − 𝑟 2
Principle behind Midpoint Circle Algorithm

We can start with a known point on the circle say


(𝑥𝑘 , 𝑦𝑘 )
. For the next x position 𝑥𝑘+1 , we can choose
between two y positions- 𝑦𝑘 or 𝑦𝑘 −1

For this octant , it has a negative slope. As x


increases, y value decreases.
Choosing the next y value is based on the
position of the midpoint relative to the circle
boundary.
Decision- If the midpoint lies inside the circle
boundary choose to plot the upper pixel else
the lower pixel.
Principle behind Midpoint Circle Algorithm
Find the midpoint - (𝑥𝑘 + 1, (𝑦𝑘 +𝑦𝑘 +1)/2) = MP(𝑥𝑘 + 1, 𝑦𝑘 −
1
2
)
Derivation
Principle behind Midpoint Circle Algorithm

Next y ( 𝑦𝑘 or 𝑦𝑘 −1) depends on the the sign of 𝑝𝑘


Next Rearranging the terms,
Problem
Find the points on a circle on its octants with the circle
centered at (5,5) and has radius of 8 units
𝑝0 = 1 − 𝑟

At each point:
Plot ( xk + 1, yk )
If pk < 0:
pk +1 = pk + 2 ( xk + 1) + 1
Plot ( xk + 1, yk − 1)
If pk >= 0:
pk +1 = pk + 2 ( xk + 1) + 1 − 2 ( yk − 1)
Problem
Find the points on a circle on its octants with the circle centered
at (5,5) and has radius of 8 units

𝑝0 = 1 − 𝑟
Mid-Point Circle Algorithm

Similarly to the case with lines, there is an


incremental algorithm for drawing circles – the
mid-point circle algorithm

n the mid-point circle algorithm we use eight-way


symmetry so only ever calculate the points for the
top right eighth of a circle, and then use
symmetry to get the rest of the points

10
General Principle Consider only
The circle function: 45° ≤  ≤ 90°
f circle (x, y) = x 2 + y 2 − r 2
and

 0 if (x,y) is inside the circle boundary



f circle (x, y) = = 0 if (x,y) is on the circle boundary
 0 if (x,y) is outside the circle boundary

11
p1 p3
yi
D(s i)
yi - 1 D(ti)
p2

xi xi + 1

After point p1, do we choose p2 or p3?

12
Bresenham’s Circle Algorithm

Define: D(si) =distance of p 3 from c ircle


D(ti) =distance of p 2 from circle

i.e. D(si) =(xi +1)2 +yi2 – r2

D(ti) =(xi +1)2 +(yi – 1)2 – r2

• Decision Parameter pi =D(si) +D(ti) so


• if pi <0 then the circle is closer to p3 (point above)
if p i ≥0 then the c ircle is closer to p 2 (point below)

13
Assume that we have
(xi+1, yi)
just plotted point (x i, y i) (xi, yi)

The next point is a


choice between (xi+1, yi)
(xi+1, yi-1)
and (xi+1, yi-1)
We would like to choose
the point that is nearest to
the actual circle
So how do we make this choice?
• The decision parameter is the circle at the
midpoint between the pixels yi and yi – 1.

pi = f circle (xi +1, yi − 12 )


= (x +1) 2 + ( y − 1 ) 2 − r 2
i i 2

• If pi <0, the midpoint is inside the circle and the


pixel yi is closer to the circle boundary.
• If pi ≥0, the midpoint is outside the circle and
the pixel yi - 1 is closer to the circle boundary.
Decision Parameters
• Decision Parameters are obtained using incremental
calculations
Note:
p i + 1 = f c irc le ( x i + 1 + 1 , y i + 1 − ) 1
2 xi+1 = xi +1

= ( x i + 2 ) 2 + ( y i +1 − 1
2
)2 − r 2

OR
p = p + 2 ( x + 1) 2 + ( y 2 − y 2 ) − ( y − yi ) + 1
i +1 i i i+1 i i+1

where yi+1 is either yi or yi-1 depending on the sign


of pi
17
The Algorithm
1. Initial values:- point(0,r) move circle origin at (0,0) by
x0 = 0, y0 = r x = x – xc and y = y – yc
2. Initial decision parameter
p =f (1,r − 1 ) =1+(r − 1 )2 −r 2 = 5 − r
0 circle 2 2 4
3. At each xi position, starting at i = 0, perform the following test:
if pi < 0, the next point is (xi + 1, yi) and
pi+1 = pi + 2xi+1 + 1
If pi ≥ 0, the next point is (xi+1, yi-1) and
pi+1 = pi + 2xi+1 + 1 – 2yi+1
where 2xi+1 = 2xi + 2 and 2yi+1 = 2yi – 2
4. Determine symmetry points in the other octants
5. Move pixel positions (x,y) onto the circular path centered on (xc, yc)
and plot the coordinates: x = x + xc, y = y + yc
6. Repeat 3 – 5 until x ≥ y
Example
To see the mid-point circle algorithm in action lets
use it to draw a circle centred at (0,0) with radius
10

p0 = 5 4 − r  1− r = 1−10 = −9
24
10
k pk (xk+1,yk+1) 2xk+1 2yk+1
9
8 0 -9 (1,10) 2 20
7
1 -6 (2,10) 4 20
6
5 2 -1 (3,10) 6 20
4 3 12 (4, 9) 8 18
3
2 4 3 (5, 8) 10 16
1 -2 (6, 8) 12 16
5
0
6 5 (7, 7)
0 1 2 3 4 5 6 7 8 9 10

You might also like