0% found this document useful (0 votes)
6 views1 page

Chapter 3

The document describes three algorithms for line generation in computer graphics: 1) The DDA (Digital Differential Analyzer) algorithm takes in two end points and calculates the difference and number of steps between them. It then increments the x and y coordinates at each step to put pixels and draw the line. 2) Bresenham's line generation algorithm also uses incremental steps but only performs integer calculations. It moves across the x-axis in intervals and chooses the closer y-coordinate at each step to follow the line. 3) No information is provided about a third algorithm. The document focuses on explaining the DDA and Bresenham's algorithms for drawing lines between two points in computer graphics.

Uploaded by

SIDDHARTH KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Chapter 3

The document describes three algorithms for line generation in computer graphics: 1) The DDA (Digital Differential Analyzer) algorithm takes in two end points and calculates the difference and number of steps between them. It then increments the x and y coordinates at each step to put pixels and draw the line. 2) Bresenham's line generation algorithm also uses incremental steps but only performs integer calculations. It moves across the x-axis in intervals and chooses the closer y-coordinate at each step to follow the line. 3) No information is provided about a third algorithm. The document focuses on explaining the DDA and Bresenham's algorithms for drawing lines between two points in computer graphics.

Uploaded by

SIDDHARTH KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

LINE GENERATION ALGORITHM

http://www.tutorialspoint.com/computer_graphics/line_generation_algorithm.htm Copyright © tutorialspoint.com

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.

Step 1 − Get the input of two end points (X 0 , Y0 ) and (X 1 , 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);
}

Bresenham’s Line Generation


The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage
of this algorithm is that, it uses only integer calculations. Moving across the x axis in unit intervals
and at each step choose between two different y coordinates.

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.

You might also like