# Line Drawing Algorithm in Computer Graphics

“The Line drawing algorithm is a graphical algorithm which is used to represent the line segment on discrete graphical media, i.e., printer and pixel-based media.”A line contains two points. The point is an important element of a line.

### Properties of a Line Drawing Algorithm

There are the following properties of a good Line Drawing Algorithm.

**An algorithm should be precise:**Each step of the algorithm must be adequately defined.**Finiteness:**An algorithm must contain finiteness. It means the algorithm stops after the execution of all steps.**Easy to understand:**An algorithm must help learners to understand the solution in a more natural way.

**Correctness:**An algorithm must be in the correct manner.**Effectiveness:**Thesteps of an algorithm must be valid and efficient.**Uniqueness:**All steps of an algorithm should be clearly and uniquely defined, and the result should be based on the given input.**Input:**A good algorithm must accept at least one or more input.**Output:**An algorithm must generate at least one output.

### Equation of the straight line

We can define a straight line with the help of the following equation.

**y= mx + a**

Where,

**(x, y**) = axis of the line.

**m **= Slope of the line.

**a = **Interception point

Let us assume we have two
points of the line (**p _{1}, q_{1}**) and (

**p**).

_{2}, q_{2}Now, we will put values of the two points in straight line equation, and we get

**y = mx + a**

**q _{2 }= mp_{2}
...(1) **

**q _{1 }= mp_{1}
+ a
...(2)**

We have from equation (1) and (2)

**q _{2 }– q_{1}
= mp_{2 }– mp_{1}**

**q _{2 }– q_{1 }=
m (p_{2 }–p_{1}) **

The value of **m = (q _{2
}– q_{1})/ (p_{2 }–p_{1})**

** m = ?q / ?p**

### Algorithms of Line Drawing

There are following algorithms used for drawing a line:

**DDA (Digital Differential Analyzer) Line Drawing Algorithm****Bresenham’s Line Drawing Algorithm****Mid-Point Line Drawing Algorithm**