Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1) was the next choice
y
k+1
= y
k
1
[y
k+1
2
y
k
2
] [(y
k+1
-1)
2
(y
k
-1)
2
] = 4.y
k
+4
p
k+1
= p
k
+ 4(x
k
y
k
)+ 10
Bresenhams Circle Algorithm
The first parameter p
0
is directly computed from:
P
k
= 2.(x
k
+1)
2
+ y
k
2
(y
k
-1)
2
2.r
2
By putting k = 0, x
k
= 0 and y
k
= r
p
0
= 2.(x
0
+1)
2
+ y
0
2
(y
0
-1)
2
2.r
2
= 2.(0
+1)
2
+ r
2
(r-1)
2
2.r
2
= 3 2.r
Bresenhams Circle Algorithm
Algorithm steps
1. Input radius r and circle center (h,k) and obtain the first
point on the circumference of the circle centered on the
origin as (x
0
,y
0
) = (0,r)
2. Set initial value of the decision parameter as p
0
= 3 2.r
3. At each x
k
starting at k = 0 , perform the following test:
If p
k
< 0 , the next point along the circle centered on (0,0)
is (x
k
+1, y
k
)
p
k+1
= p
k
+ 4x
k
+ 6
else //the next point along the circle centered on (0,0) is
(x
k
+1, y
k
-1)
p
k+1
= p
k
+ 4x
k
4y
k
+ 10;
y
k
= y
k
1
4. Increment x
k
= x
k
+ 1
5. Plot circle pixels using 8-way symmetry centred on (h,k)
6. Repeat steps 3 through 5 until x <= y
Circle Drawing Algorithms
1. Polynomial Method
2. Trigonometric Method
3. Bresenham Circle Algorithm
4. Midpoint Circle Algorithm
Midpoint Circle Algorithm
1. Introduction
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 implicit equation of
the circle.
Integer calculations are used to compute the circle points in
one octant, rest of the seven points are plotted using eight
way symmetry.
The equations derived will be similar to Bresenhams circle
algorithm
Midpoint Circle Algorithm
2. Basic Concept
We will first calculate pixel positions for a circle centered
around the origin (0,0). Centre is shifted later on.
Note that along the circle section from x=0 to x=y in the first
octant, the slope of the curve varies from 0 to -1
Circle function around the origin is given by
f
circle
(x,y) = x
2
+ y
2
r
2
Any point (x,y) on the boundary of the circle satisfies the
equation and circle function is zero
Midpoint Circle Algorithm
For a point in the interior of the circle, the circle function is
negative and for a point outside the circle, the function is
positive
Thus, we have a discriminator function
f
circle
(x,y) < 0 if (x,y) is inside the circle boundary
f
circle
(x,y) = 0 if (x,y) is on the circle boundary
f
circle
(x,y) > 0 if (x,y) is outside the circle boundary
The algorithm does the above test at mid point f
circle
(x,y-), if
it lies inside outer point is plotted, else inner is considered to be
the better choice
Midpoint Circle Algorithm
6
2 3 4 1
5
4
3
Midpoint Circle Algorithm
M
6
2 3 4 1
5
4
3
Midpoint Circle Algorithm
M
6
2 3 4 1
5
4
3
Midpoint Circle Algorithm
3. Derivation
Let us assume that P(x
k
, y
k
)
is the currently plotted pixel.
Q(x
k+1
, y
k+1
) (x
k+1
, y ) is
the next point along the actual
circle path. We need to decide
next pixel to be plotted from
among candidate positions
Q1(x
k
+1, y
k
) or
Q2(x
k
+1, y
k
-1)
Midpoint Circle Algorithm
Our decision parameter is the circle function evaluated at
the midpoint between these two pixels
p
k
= f
circle
(x
k
+1, y
k
-1/2) = (x
k
+1)
2
+ (y
k
-1/2)
2
r
2
If p
k
< 0 ,
this midpoint is inside the circle and
the pixel on the scan line y
k
is closer to the circle boundary.
Otherwise,
the mid position is outside or on the circle boundary,
and we select the pixel on the scan line y
k
-1
Midpoint Circle Algorithm
Successive decision parameters are obtained using incremental
calculations
p
k
= (x
k
+1)
2
+ (y
k
)
2
r
2
Put k = k+1
p
k+1
= [(x
k+1
)+1]
2
+ (y
k+1
)
2
r
2
= (x
k
+2)
2
+ (y
k+1
)
2
r
2
subtracting p
k
from p
k+1
p
k+1
P
k
= (x
k
+2)
2
+ (y
k+1
)
2
[(x
k
+1)
2
+ (y
k
)
2
]
or
p
k+1
= P
k
+2(x
k
+1) + (y
k+1
)
2
(y
k
)
2
+1
Where y
k+1
is either y
k
or y
k-1
, depending on the sign of p
k
Midpoint Circle Algorithm
If p
k
< 0
Q1(x
k
+1, y
k
) was the next choice
y
k+1
= y
k
(y
k+1
)
2
(y
k
)
2
= 0
p
k+1
= p
k
+ 2.x
k
+3
else
Q2(x
k
+1, y
k
-1) was the next choice
y
k+1
= y
k
+1
(y
k+1
)
2
(y
k
)
2
= 2.y
k
+2
p
k+1
= p
k
+ 2(x
k
y
k
)+ 5
Midpoint circle algorithm
Initial decision parameter is obtained by evaluating the circle
function at the start position (x0,y0) = (0,r)
p
0
= f
circle
(1, r 1/2)
= 1+ (r 1/2)
2
r
2
= 5/4 r
If radius r is specified as an integer, we can round p
0
to
p
0
= 1 r
Midpoint Circle Algorithm
4. Algorithm steps
1. Input radius r and circle center (h,k) and obtain the first
point on the circumference of the circle centered on the origin
as (x
0
,y
0
) = (0,r)
2. Set initial value of the decision parameter as p
0
= 1 r
3. At each x
k
starting at k = 0 , perform the following test:
If p
k
< 0 , //the next point along the circle centered on (0,0)
is (x
k
+1, y
k
)
p
k+1
= p
k
+ 2x
k
+ 3
else //the next point along the circle centered on (0,0)
is (x
k
+1, y
k
-1)
p
k+1
= p
k
+ 2x
k
2y
k
+ 5;
y
k
= y
k
1
4. Increment x
k
= x
k
+ 1
5. Plot circle pixels using 8-way symmetry centred on (h,k)
6. Repeat steps 3 through 5 until x <= y