# Explain Bresenhams Line Drawing Algorithm?

1 month ago

**Bresenhams line drawing algorithm**

In Bresenham’s approach the pixel position along a line path are determined by sampling unit X intervals.

Starting from the left end point(X_{0}, Y_{0})of a given line we step to each successive columns and plot the pixel whose scan line Y-value is closest to the line path.Assuming the K^{th} step in process, determined that the pixel at (X_{k}, Y_{k})decide which pixel to plot in column X_{k+1}.

The choices are (X_{k+1,} Y_{k}) and (X_{k+1}, Yk+1)

**Algorithm**

**Step 1: **Input the line endpoints and store the left endpoint in (X_{0}, Y_{0}) Step 2: Load (X_{0}, Y_{0}) in to the frame buffer.

**Step 3: **Calculate constants x, y, 2 y, -2 x, and obtain the decision parameters as

P0 = 2 y – x

**Step 4 :** At each X_{k} along the line, starting at k = 0, perform the following test If Pk < 0, the next point to plot is (X_{k+1,} Y_{k}) and

P_{k+1} = P_{k}+2 y

Otherwise, the next point to plot is (X_{k+1}, Y_{k+1}) and

P_{k+1} = P_{k}+2 y - 2 x

**Step 5:** Repeat step 4 x times

###### Rajiv Bikram

Oct 20, 2021