Algo
Algo
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
Step 1: Start.
Step 2: Declare x, y, r, xc, yc and d as variables, where ( xc , yc ) are coordinates of the center.
Step 5: If x >= y
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.
If d < 0, set d = d + (4 * x) + 6.