0% found this document useful (0 votes)
10 views2 pages

DDA Line Drawing Algorithm Explained

The document explains the Digital Differential Analyzer (DDA) algorithm for line generation in graphics, detailing the steps to calculate the necessary increments and draw a line between two points. It includes a Java method exercise to implement the DDA algorithm and create a graphical representation. References for further reading and tutorials are also provided.

Uploaded by

sarath perera
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

DDA Line Drawing Algorithm Explained

The document explains the Digital Differential Analyzer (DDA) algorithm for line generation in graphics, detailing the steps to calculate the necessary increments and draw a line between two points. It includes a Java method exercise to implement the DDA algorithm and create a graphical representation. References for further reading and tutorials are also provided.

Uploaded by

sarath perera
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

B.

Christopaul
DDA Algorithm [Link] Edu (Physics), [Link] (Computer Science), [Link], Dip in Edu

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 X0, Y0 and the second point of line as X 1, Y1.

Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm which is
explained step by step here.

Step 1: Get the input of two end points (X0, Y0) and (X1, Y1).
Step 2: Calculate the difference between two end points.
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.
if (dx > dy)
Steps = absolute(dx);
else
Steps = absolute(dy);
Step 4: Calculate the increment in x coordinate and y coordinate.
Xincrement = dx / (float) steps;
Yincrement = dy / (float) steps;

Step 5: Put the pixel by successfully incrementing x and y coordinates accordingly and
complete the drawing of the line.
for(int v=0; v < Steps; v++){
x = x + Xincrement;
y = y + Yincrement;
putpixel(x,y);
}

Exercise:
Write a Java method called DDRAlg(Graphics g, int x0, int y0, int xl, int yl) to implement the DDA line drawing
algorithm, where (x0, y0) and (xl, y1) are end points of the line.

Write a Java coding to create the picture as given below using the above line drawing methods. Display them in
the center of the screen.

1. 2.

References:
 Computer Graphics Tutorial Tutorialspoint – Page 10
 [Link]


 Youtube: [Link]

You might also like