## What is Bresenham Line Drawing Algorithm?

The Bresenham line drawing algorithm determines the points of the N-dimensional raster selected to generate the close approximation to the straight line between the two coordinates or points. In the Bresenham line drawing algorithm, the integer is only for addition, subtraction, and multiplication.

The operation in the Bresenham line drawing algorithm is performed quickly so the line can be generated quickly. Suppose the line equation is y = mx + c. If the slope(m) value is 1, both the coordinate incremented, but if the slope value is less than 1, then the y coordinate may or may not be incremented. The Bresenham line drawing algorithm is used where the slope value is not equal to one.

Download Formulas for GATE Computer Science Engineering - Discrete Mathematics

## Bresenham Line Drawing Algorithm Derivation

The Bresenham line drawing algorithm takes four integer values that are x_{1}, y_{1}, x_{2}, and y_{2}. The Bresenham line drawing algorithm given below is for the slope value less than one that is as follows:

Algorithm_bresenham(x_{1}, y_{1}, x_{2}, y_{2})

{

x= x_{1};

y=y_{1};

dx = x_{2} – x_{2};

dy = y_{2} – y_{1};

p = 2dx = dy;

while(x <= x_{2})

{

putpixel(x,y);

x++;

if(p<0)

p=p+2dx;

else

p=p + 2dy – 2dx;

y++;

}

}

## Need of Bresenham Line Drawing Algorithm

The Bresenham line drawing algorithm is needed to overcome the problem of floating points in the DDA (Digital Differential Analyzer) that is for the DDA algorithms, the equations are:

- For X-axis Δx = x
_{2}– x_{1} - For Y-axis Δy = y
_{2}– y_{1}

Step = max(Δx, Δy)

X_{inc} = Δx/step

Y_{inc} = Δy/step

As in the above equation, the division operation is used, which returns the float value. The float takes more time for addition, subtraction, and multiplication than an integer. Therefore, the Bresenham line drawing algorithm is used to overcome the floating-point problem.

## Advantages of the Bresenham Line Drawing Algorithm

The advantage of the Bresenham line drawing Algorithm is that the Bresenham line drawing algorithm is easy to implement. It is very fast to execute but less than the DDA(Digital Differential Analyzer) algorithm and incremental.

The points generated by the Bresenham line drawing algorithm are more correct or accurate than DDA(Digital Differential Analyzer) Algorithm. The Bresenham line drawing algorithm uses fixed points or coordinates only.

Download Formulas for GATE Computer Science Engineering - Algorithms

### How is the Decision Parameter Calculated in the Bresenham Line Drawing Algorithm?

The decision parameter calculated in the Bresenham line drawing algorithm** for slope |m|>1 is as follows:**

1. Input two endpoints or coordinates of the line (x_{1},y_{1}) and (x_{2},y_{2}).

2. The first point (x_{1},y_{1}) is plotted on the graph or screen.

3. Now calculate the difference in X and Y coordinates, that is: dx =|x_{2} – x_{1}| dy = |y_{2} – y_{1} |

4. The initial decision parameter will be calculated as aa: p = 2*dx – dy.

5. For I = 0 to dy in step 1.

If p < 0 then

the Y coordinate incremented as y_{1} = y_{1} + 1 and then plot(x_{1},y_{1}).

Calculate new decision parameter as p = p + 2dx.

Else

the X coordinate incremented as x_{1} = x_{1} + 1

the Y coordinate incremented as y_{1} = y_{1} + 1

and then plot(x_{1}, y_{1})

Calculate new decision parameter as p = p + 2dx – 2*dy

6. END

Important Topics for Gate Exam | |

Brittle Material | Capacitors in Parallel |

Capacitors in Series | Carnot Cycle |

Cement Test | Clamping Circuit |

Clipping Circuit | CMOS Fabrication |

CMOS Converter | Column Base |

## Comments

write a comment