### Bresenham Line Drawing Algorithm Solved Example

We have three most popular line drawing algorithms in computer graphics.

1. DDA Line Drawing Algorithm

2. Bresenham Line Drawing Algorithm

3. Mid Point Line Drawing Algorithm

In this tutorial we will disscuss the Bresenham line algorithm and also, solve a numarical example using Bresenham algorithm.

### Bresenham Algorithm

Bresenham Line Drawing Algorithm is one of the simplest and most powerful line drawing algorithm in computer graphics. This algorithm overcomes the disadvantages of DDA algorithm.

Given –

Starting coordinates = (X_{0}, Y_{0})

Ending coordinates = (X_{n}, Y_{n})

A four-step approach is followed to generate the line.

**Step 1:**

Calculate parameters ΔX, ΔY and M from the given input.

These parameters are calculated as –

ΔX = X_{n} – X_{0}

ΔY =Y_{n} – Y_{0}

**Step 2:**

Calculate the decision parameter P_{k}.

It is calculated as – P_{k} = 2ΔY – ΔX

This decision variable is used to dicide, whether x coordinate should be incremented or y coordinate should be increamented or both.

**Step 3:**

Suppose the current point is (X_{k}, Y_{k}) and the next point is (X_{k+1}, Y_{k+1}).

Find the next point by following the below three cases –

**Case 1: if (P _{k}<0)**

X_{k+1}= X_{k} + 1

Y_{k+1}= Y_{k}

P_{k+1} = P_{k} + 2ΔY

**Case 2: if (P _{k} >= 0)**

X_{k+1}= X_{k} + 1

Y_{k+1}= Y_{k} + 1

P_{k+1} = P_{k} + 2ΔY – 2ΔX

**Step 4:**

**P _{k+1}** will become the decision parameter for the next iteration. (

**X**,

_{k+1}**Y**) is the (

_{k+1}**X**,

_{k+1}**Y**) in the next iteration. Keep repeating Step-03 until the endpoint is reached or the number of iterations equals to (ΔX-1) times.

_{k+1}## Video Tutorial Bresenham Line Drawing algorithm Algorithm:

## 1. Solved Example Bresenham Line drawing Algorithm

## Video Tutorial MidPoint Line Drawing algorithm Algorithm:

## 1. Solved Example MidPointLine drawing Algorithm

## Video Tutorial DDA Algorithm:

## 1. Solved Example DDA Algorithm

## 2. Solved Example DDA Algorithm

## 3. Solved Example DDA Algorithm

Bresenham Line Drawing Algorithm Solved Example: If you like the material share it with your friends. Like the **Facebook page** for regular updates and **YouTube channel** for video tutorials.