DAA (Digital Differential Analyser) Line Generation Algorithm
In any 2-Dimensional plane when we connect two points (x0, y0) and (x1,y1), we get a line segment. But in the case of computer graphics we can not directly join any two coordinate points, for that we should calculate the number of steps between and the x and y increment value to put the pixel.
Algorithm:
(x0,y0) // starting point of the line
(x1,y1) // end point of line
dx=x1-x0
dy=y1-y0
if (dx>dy):
steps=dx //calculate the no of steps between intial and final points
else:
steps=dy
xinc=dx/steps // calculate the x and y increments
yinc=dy/steps
x=x0 // initialize x and y to intial x and y values
y=y0
for (i=0,i<=steps;i++)
{
putpixel(x,y,BLACK) //print the pixel
x=x+xinc // increment x coordinate
y=y+yinc // increment y coordinate
}
This comment has been removed by the author.
ReplyDeleteOnnichan <3
ReplyDelete