Digital differential analyzer (graphics algorithm)

This is an old revision of this page, as edited by SmackBot (talk | contribs) at 13:58, 15 August 2007 (Date/fix the maintenance tags or gen fixes). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Digital Differential Analyzer (DDA)

DDA (digital differential analyzer) is used for generating pixels using a line formed by two 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. Here is a sample C code of the DDA implementation:

Sample Code

{{citation}}: Empty citation (help) 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));
           }

}