DDA(Digital Differential Analyzer) Algorithm

ALGORITHM : DDALine ( X1, Y1, XN, YN)
Here X1 and X2 denotes starting X and Y coordinates,whereas XN and YN denotes ending X and Y coordinates of the line.M is the slope of the line,DX and DY are change in X and Y coordinates respectively.

1.Set M = (YN – Y1) / (XN – X1). [Slope Of Line]
2.Set I=X1.[Initialize Counter ]
3.Repeat steps 4,5 and 6 while I <=XN.
4.If (M <= 1) Then
Set DX = 1 and Set DY = M * DX
Else
Set DY = 1 and Set DX = DY / M
[End Of If.]
5.Set X1 = X1 + DX and Set Y1 = Y1 + DY.
6.Call PutPixel(X1, Y1)
7.Set I=I+1.[Increment Counter]
[End Of Loop.]
8.Exit.


If you have any suggestions regarding this post, please comment below in the comment section.

2 comments

Followers