# Bresenham’s Line Algorithm

Bresenham’s Line Algorithm was developed by **Bresenham**. It is more accurate and efficient compared to the DDA algorithm because it cleverly avoids the “Round” function and it scan and converts line using only incremental integer calculation.

This algorithm samples a line by incrementing by one unit either x or y depending on the slope of the line and then selects the pixel lying at least distance from the true line path at each sampling position.

To illustrate Bresenham’s approach, let us consider a line (L) with a positive slope of less than 1. So, the line will be sampled at unit intervals in the X-direction. Assuming we have already determined that the pixel at (x_{k}, y_{k}) is to be displayed, we next need to decide which pixel to plot at next sampling position at x_{k}+1 grid line.

_{1}, y

_{1}) and (x

_{2}, y

_{2})

2. Calculate constants:

**Δx=x**

_{2}– x_{1}**Δy=y**

_{2}– y_{1}2Δy

2Δy-Δx

3. Assign value to the starting parameter :

k=0

**P**

_{0}=2Δy-Δx4. Plot the pixel at (x

_{1}, y

_{1})

5. For each integer X Co-ordinate, X

_{k}along the line.

if P

_{k}<0, the next point to plot is (x

_{k}+1, y

_{k})

**P**

_{k+1}=P_{k}+2Δyelse

the next point to plot is (x

_{k}+1, y

_{k}+1)

**P**

_{k+1}=P_{k}+2Δy-2Δx6. Repeat Step 5 Δx lines.