Bresenham’s Line Algorithm
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 a 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 (xk, yk) is to be displayed, we next need to decide which pixel to plot at the next sampling position at xk+1 grid line.
1. Input two line endpoints (x1, y1) and (x2, y2)
2. Calculate constants:
Δx=x2 – x1
Δy=y2 – y1
3. Assign the value to the starting parameter :
4. Plot the pixel at (x1, y1)
5. For each integer X Co-ordinate, Xk along the line.
if Pk<0, the next point to plot is (xk+1, yk)
the next point to plot is (xk+1, yk+1)
6. Repeat Step 5 Δx lines.