Bresenham N Circle Algorithm
Bresenham N Circle Algorithm
Bresenham N Circle Algorithm
(30,18)
dx = 10, dy = 8
initial decision d0 = 2dy dx =
6
2(dy dx) = -4
iAlso
d 2dy
(x =
,y 16,
)
i
0
1
2
3
4
5
6
7
8
9
6
2
-2
14
10
6
2
-2
14
10
i+1
i+1
(21,11)
(22,12)
(23,12)
(24,13)
(25,14)
(26,15)
(27,16)
(28,16)
(29,17)
(30,18)
(20,10)
19
18
17
16
15
14
13
12
Circle Generating
Algorithms
Circle Properties:
A set of points that are all at the same distance
(r) from a center point (xc,yc).
Expressed by Pythagorean equation in Cartesian
coordinates as:
(x xc )2 + (y - yc )2 = r2
Circle Generating
Algorithms:
Standard Algorithm
Polar Algorithm
Symmetry Algorithm
Mid-point Algorithm
(xc,
yc )
(x, y)
Standard Algorithm:
Uses the Pythagorean equation to
find
the
points
along
the
circumference.
Steps along x axis by unit steps from
xc-r to xc+r and calculate y for each
step as:
y= yc r2-(xc-yc)2
Standard Algorithm:
Spacing between plotted pixels is not uniform.
Polar Algorithm:
Uses polar coordinates r and .
Calculate points by fixed regular step size
equations as:
x= xc + r * cos
y= yc + r * sin
Step size that is chosen for depends on the
application.
Larger separations can be connected by line
segments to approximate the circle path.
Polar Algorithm:
In raster displays, step size is 1/r which plots
pixel positions that are approximately one unit
apart.
x,y
r
Symmetry Algorithm:
Reduces computations by considering the
symmetry of circles in the eight octants in
the xy plane.
Generates all pixel positions
around a circle by calculating
only the points within the
sector from x = 0 to x = y.
Consider only
45 90
General Principle
The circle function:
f circle ( x, y ) x 2 y 2 r 2
and
0 if (x,y) is inside the circle boundary
11
p1
p3
yi - 1
p2
D(si)
D(ti)
r
xi xi + 1
After point p1, do we choose p2 or p3?
12
The Algorithm
x0 = 0
y0 = r
p0 = [12 + r2 r2] + [12 + (r-1)2 r2] = 3
2r
if pi < 0 then
yi+1 = yi
pi+1 = pi + 4xi + 6
xi+1 = xi + 1
else if pi 0 then
yi+1 = yi 1
pi+1 = pi + 4(xi yi) + 10
Stop when xi yi and determine
symmetry points in the other octants14
Mid-point Algorithm:
Samples at unit intervals and uses decision parameter to
determine the closest pixel position to the specified circle
path at each step.
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.
Mid-point Algorithm:
To apply mid-point method, we define a circle
function:
Mid-point Algorithm:
If pk < 0, this midpoint is inside the circle and the
pixel on scan line yk is closer to the circle boundary.
Otherwise, the midposition is outside or on the circle
boundary, and we select the pixel on scan line yk 1 .
Successive parameters
incremental calculations:
are
calculated
using
Mid-point Algorithm:
Example:
For a circle radius=10 and center (12,12)
we calculate positions in the first octant only , beginning
with x=0 and ending when x=y
The initial decision parameter value:
P0=1 - r = -9
Drawing on the origin (0,0) and the initial point (0,10)
2x0=0 2y0=20
Mid-point Algorithm:
K P (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
The
first
octant
is
completed
and
the
remained seven octants
can be plotted according
to symmetry.
2
4
2
3
2
2
2
1
2
0
1
9
1
8
1
7
1
6
1
5
1
4
1
3
1
2
1
1
1
0
9
8
2 3
4 5 6
7 8
9 10 11 12 13 14 15 16 17 18 19 20
Mid-point Algorithm:
The circle after plotting
all octants and moving it
to its original center
(12,12)
2
4
2
3
2
2
2
1
2
0
1
9
1
8
1
7
1
6
1
5
1
4
1
3
1
2
1
1
1
0
9
8
2 3
4 5 6
7 8
9 10 11 12 13 14 15 16 17 18 19 20
Example
r = 10
p0 = 3 2r = -17
Initial point (x0, y0) = (0, 10)
i
pi
xi, yi
-17
(0, 10)
-11
(1, 10)
10
9
-1
(2, 10)
13
(3, 10)
-5
(4, 9)
15
(5, 9)
6
7
(6, 8)
(7,7)
21