DDA Algorithm:
The Digital differential analyzer is a scan conversion line algorithm based on
calculating either Δy or Δx, using Δy=m. Δx or Δx= Δy/m.
We sample the line at unit intervals in one co-ordinate and determine corresponding
integer values nearest the line path for the other co-ordinate.
Consider first a line with a positive slope.
Step 1:
If the slope is less than or equal to 1, we sample at unit x intervals (Δx=1)
and compute each successive y value as
Δx=1
m = Δy / Δx
m = ( y2-y1 ) / 1
m = ( yk+1 – yk ) /1
yk+1 = yk + m
K – takes integer values starting from 1, for the first point, and increases by 1
until the final endpoint is reached.
M - can be any real number between 0 and 1,
The calculated y values must be rounded to the nearest integer.
Step 2:
For lines with a positive slope greater than 1, we reverse the roles of x and y. That
is, we sample at unit y intervals (Δy=1) and calculate each succeeding x value as
Δy=1
m= Δy / Δx
m= 1/ ( x2-x1 )
m = 1 / ( xk+1 – xk )
xk+1 = xk + 1/m
Step : 3
If the processing is reversed, the starting point at the right, Δx=-1
m= Δy / Δx
m = ( y2 – y1 ) / -1
yk+1 = yk - m
Step 4:
or we have Δy= -1 with
xk+1=xk-1/m
This algorithm is summarized in the following procedure, which accepts as input the
two endpoint positions. Horizontal and vertical differences between the endpoint
positions are assigned to parameters dx and dy. The difference with the greater
magnitude