Bresenham Line Drawing Algorithm C Program

 

Let us understand what is Bresenham line algorithm in computer graphics and then let us see how to implement Bresenham line drawing algorithm in C programming using different methods.

What is Bresenham Line Algorithm?

The Bresenham’s line drawing algorithm constructs a straight line using close approximation between the points on an n-dimensional bitmap image. It was actually developed to sketch lines on digital plotters but due to its extensibility and versatility, it was found to be useful for computer graphics as well.

 

It was actually developed to sketch lines on digital plotters but due to its extensibility and versatility, it was found to be useful for computer graphics as well. It makes use of pixels concept to draw a curve or a straight line.

It is a highly efficient incremental method to scan and convert the lines as compared to the DDA line drawing algorithm. However, it requires the line coordinates to be of integer type.

The Bresenham algorithm is extremely simple to implement. Along with this, it also provides speed and efficiency. This makes it applicable in many domains such as:

  1. Graphic cards
  2. Firmware
  3. Graphical libraries
  4. graphics hardware

Assumptions:

  • The slope of the line is between 0 and 1
  • x1 < x2 and y1 < y2
  • The line is sketched from lower left to top right

Algorithm for Bresenham’s Line

   

If you face any issues while compiling this line drawing graphics program, you may have to install graphics.h in your operating system.

Note: This C program for Bresenham line generation algorithm is compiled with Turbo C compiler on Microsoft Windows 10 operating system.

   

Method 1: C Program To Implement Bresenham Line Drawing Algorithm

Method 2: Bresenham line drawing algorithm in C Programming using Function

Output

Enter X-axis coordinate of the initial point: 20
Enter Y-axis coordinate of the initial point: 30
Enter X-axis coordinate of the final point: 70
Enter Y-axis coordinate of the final point: 90

Implement Bresenham Line Drawing Algorithm in C Programming using Functions with Output and Explanation

Let us discuss more on this Bresenham line drawing algorithm in C programming in the comment section below.

Do let us know if you have any doubts or have any information to share. For information, check Wikipedia.

Let's Discuss