Chapter 3
Chapter 3
A line connects two points. It is a basic element in graphics. To draw a line, you need two points
between which you can draw a line. In the following three algorithms, we refer the one point of line
as X 0 , Y0 and the second point of line as X 1 , Y1 .
DDA Algorithm
Digital Differential Analyzer DDA algorithm is the simple line generation algorithm which is
explained step by step here.
dx = X1 - X0
dy = Y1 - Y0
Step 3 − Based on the calculated difference in step-2, you need to identify the number of steps to
put pixel. If dx > dy, then you need more steps in x coordinate; otherwise in y coordinate.
Step 5 − Put the pixel by successfully incrementing x and y coordinates accordingly and complete
the drawing of the line.
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.