“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
(x, y) = axis of the line.
m = Slope of the line.
a = Interception point
Let us assume we have two points of the line (p1, q1) and (p2, q2).
Now, we will put values of the two points in straight line equation, and we get
y = mx + a
q2 = mp2 …(1)
q1 = mp1 + a …(2)
We have from equation (1) and (2)
q2 – q1 = mp2 – mp1
q2 – q1 = m (p2 –p1)
The value of m = (q2 – q1)/ (p2 –p1)
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