Line Drawing is done by calculating Intermediate positions along the line path Between specified paths. DDA LINE Algorithm is a simplest algorithm of drawing a line . In DDA Algorithm line is simply Draws by adding the increment to initial pixel values with respect to x and y direction . After drawing initial pixel whose x and y direction are entered by user or inputted by user Then the Next pixel is drawn by adding Change in x and y direction of new pixel to the initial pixel
We will add the value of change in x and y axis to initial or previous x and y axis values to get New pixel plotted on screen and This process continues upto and end point that is also inputted by user at start of execution of This Algorithm
The Screen Locations are refrenced by integer values and if these values are in fraction like 10.25 and 21.4 :- (10.25,21.4) where 10.25 is x coordinate in x-Axis and 21.4 is Y Coordinate in Y-Axis Then These Fractional Values will be converted into Integer values on Screen and interpreted as (10,21). This rounding of two integers cause lines to be displayed with stare steps appearance in Zagged line
To Display a pixel on Screen we use
putpixel ( 10 , 11 )How Line Drawn in DDA Line Algorithm
1. First user input the four values
* Initial pixel value in x-direction { let x1 }
* Initial pixel value in y-direction { let y1 }
* End Point pixel value in x-direction { let x2 }
* End Point pixel value in y-direction { let y2 }
2. Now all inputs are given , Now first input the initial pixels point
putpixel ( x1, y1 )
3. Now we will add the an increment value to initial x and y coordinates and this increment value is added upto End Point
4. The Increment value is calculated by
dx = x2 - x1 // In x-Direction
dy = y2 - y1 // In y-Direction
Here dx is the how much total distance to cover in x-direction to reach the End coordinate in x-direction
Here dy is the how much distance to cover in y-direction to reach the End coordinate in y-direction
5. Now find the how must distance to cover at one time or at one loop run
6. This is calculated by dividing the dx and dy by a step
7. value of step will be value among dx or dy
If dx > dy then
{
step = dx
}
else
{
step = dy
}
8. After calculating step change in x-direction let be cx will be
cx = dx/step
This will give how much distance to cover in each loop run or at one time how much increment will takes place
Similarly in y-direction
cy = dy/step
This will give how much distance to cover in each loop run or at one time how much increment will takes place
9. Now Start a loop and it will continue upto value in Step variable
increment x and y as :-
x= cx + x
y= cy + y
setpixel ( x , y ) // Put or set the New pixel
10. Now at execution of Loop the line will be printed
For Any query feel free and post the question you will get feedback within 2 hours