What is Bresenham Algorithm ?

The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage of this algorithm is that, it uses only integer calculations. Moving across the x axis in unit intervals and at each step choose between two different y coordinates.

For example, as shown in the following illustration, from position (2, 3) you need to choose between (3, 3) and (3, 4). You would like the point that is closer to the original line.

Bresenham’s Line Generation

At sample position Xk+1,Xk+1, the vertical separations from the mathematical line are labelled as dupperdupper and dlowerdlower.

dupper and dlower

From the above illustration, the y coordinate on the mathematical line at xk+1xk+1is −

Y = m(XkXk+1) + b

So, dupperdupper and dlowerdlower are given as follows −





You can use these to make a simple decision about which pixel is closer to the mathematical line. This simple decision is based on the difference between the two pixel positions.


Let us substitute m with dy/dx where dx and dy are the differences between the end-points.


So, a decision parameter PkPk for the kth step along a line is given by −


The sign of the decision parameter PkPk is the same as that of dlowerdupperdlower−dupper.

If pkpk is negative, then choose the lower pixel, otherwise choose the upper pixel.

Remember, the coordinate changes occur along the x axis in unit steps, so you can do everything with integer calculations. At step k+1, the decision parameter is given as −


Subtracting pkpk from this we get −


But, xk+1xk+1 is the same as (xk)+1(xk)+1. So −


Where, Yk+1YkYk+1–Yk is either 0 or 1 depending on the sign of PkPk.

The first decision parameter p0p0 is evaluated at (x0,y0)(x0,y0) is given as −


Now, keeping in mind all the above points and calculations, here is the Bresenham algorithm for slope m < 1 −

Step 1 − Input the two end-points of line, storing the left end-point in (x0,y0)(x0,y0).

Step 2 − Plot the point (x0,y0)(x0,y0).

Step 3 − Calculate the constants dx, dy, 2dy, and (2dy – 2dx) and get the first value for the decision parameter as −


Step 4 − At each XkXk along the line, starting at k = 0, perform the following test −

If pkpk < 0, the next point to plot is (xk+1,yk)(xk+1,yk) and




Step 5 − Repeat step 4 (dx – 1) times.

For m > 1, find out whether you need to increment x while incrementing y each time.

After solving, the equation for decision parameter PkPk will be very similar, just the x and y in the equation gets interchanged.

know more at : https://www.tutorialspoint.com


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s