This article needs additional citations for verification. (August 2007) |
This article provides insufficient context for those unfamiliar with the subject. |
In Computer graphics, Digital Differential Analyzer (DDA) is an algorithm used to determine which points need to be plotted in order to draw a straight line between two given points. It employees the equation for line representation (example: y=mx+c), then scan through an axis. Each scan it would determine the value on the other axis using the equation, this way the proper pixel can be located.
The DDA method is not very efficient due to the need for division and rounding. Bresenham's line algorithm is a more efficient method to draw lines because it uses only addition, subtraction and bit shifting.
Sample Code
{{citation}}
: Empty citation (help)
This is a sample DDA implementation in the C programming language:
void line DDA(int xa, int ya, int xb, int yb) { int dx=xb-xa, dy=yb-ya, steps, k; float xIncrement, yIncrement, x=xa, y=ya; if(abs(dx)>abs(dy)) steps=abs(dx); else steps=abs(dy); xIncrement=dx/(float)steps; yIncrement=dy/(float)steps; setPixel(ROUND(x), ROUND(y)); for(k=0; k<steps; k++) { x += xIncrement; y += yIncrement; setPixel(ROUND(x), ROUND(y)); } }