Digital differential analyzer (graphics algorithm): Difference between revisions

Content deleted Content added
NOTHING
No edit summary
Line 19:
 
== Algorithm ==
Write line function instead it is more easy,efficent Vivekanand ROX...
A linear DDA starts by calculating the smaller of dy or dx for a unit increment of the other. A line is then sampled at unit intervals in one coordinate and corresponding integer values nearest the line path are determined for the other coordinate.
 
Considering a line with positive slope, if the slope is less than or equal to 1, we sample at unit x intervals (dx=1) and compute successive y values as
: <math>y_{k+1} = y_k + m</math>
: <math>x_{k+1} = x_k + 1</math>
 
Subscript k takes integer values starting from 0, for the 1st point and increases by 1 until endpoint is reached.
y value is rounded off to nearest integer to correspond to a screen pixel.
 
For lines with slope greater than 1, we reverse the role of x and y i.e. we sample at dy=1 and calculate consecutive x values as
: <math>x_{k+1} = x_k + \frac{1}{m}</math>
: <math>y_{k+1} = y_k + 1</math>
 
Similar calculations are carried out to determine pixel positions along a line with negative slope. Thus, if the absolute value of the slope is less than 1, we set dx=1 if <math> x_{start}<x_{end}</math> i.e. the starting extreme point is at the left.
 
== See also ==