Bresenham algorithm for slope m < 1 −
Step 1 − Input the two end-points of line, storing the left end-
point in (x0,y0)(x0,y0).
Step 2 − Plot the point (x0,y0)(x0,y0).
Step 3 − Calculate the constants dx, dy, 2dy, and 2dy–2dx2dy–
2dx and get the first value for the decision parameter as −
p0=2dy−dxp0=2dy−dx
Step 4 − At each Xk along the line, starting at k = 0, perform
the following test −
If pk< 0, the next point to plot is (xk+1,yk) and
pk+1=pk+2dy
Otherwise,
(xk,yk+1)
pk+1=pk+2dy−2dx
Step 5 − Repeat step 4 dx–1.
Mid Point Algorithm
Step 1 − Input radius r and circle center (xc,yc) and obtain the
first point on the circumference of the circle centered on the
origin as
(x0, y0) = (0, r)
Step 2 − Calculate the initial value of decision parameter as
Po = 5/4 – r
Step 3 − At each XK position starting at K=0, perform the
following test −
If PK < 0 then next point on circle (0,0) is (XK+1,YK) and
PK+1 = PK + 2XK+1 + 1
Else
PK+1 = PK + 2XK+1 + 1 – 2YK+1
Where, 2XK+1 = 2XK+2 and 2YK+1 = 2YK-2.
Step 4 − Determine the symmetry points in other seven
octants.
Step 5 − Move each calculate pixel position X,Y onto the
circular path centered on (XC,YC) and plot the coordinate
values.
X = X + XC, Y = Y + YC
Step 6 − Repeat step-3 through 5 until X >= Y.
Bresenham’s Circle Drawing Algorithm
Step 1: Start.
Step 2: Declare x, y, r, xc, yc and d as variables, where ( xc , yc ) are coordinates of the center.
Step 3: Calculate the decision parameter as follows: D = 3 - 2r
Step 4: Initialize x=0,y=r
Step 5: If x >= y
Plot eight points by using concepts of eight-way symmetry.
Step 6: If D < 0
then D = D + 4x + 6
x=x+1
If D ≥ 0
then D = D+ 4 (x - y) + 10
x=x+1
y=y-1
Step 7: End.
This was the entire explanation and working of the Bresenham's algorithm. Now, let us have a look at
the advantages and disadvantages offered by this algorithm.
1. Set initial values of (xc, yc) and (x, y).
2. Set the decision parameter d to d = 3 – (2 * r).
3. Call the drawCircle(int xc, int yc, int x, int y) function.
4. Repeat the following steps until x <= y:
If d < 0, set d = d + (4 * x) + 6.
Else, set d = d + 4 * (x – y) + 10 and decrement y by 1.
Increment the value of x.
Call the drawCircle(int xc, int yc, int x, int y) function.