ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
Digital Differential Analyzer (graphics algorithm) - Wikipedia, the free encyclopedia

Digital Differential Analyzer (graphics algorithm)

From Wikipedia, the free encyclopedia

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 employs 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.

Contents

[edit] Overview

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.

[edit] The algorithm in code

  This is a sample implementation of the DDA algorithm in the C programming language:

/* Draw a straight line between the points (xa, ya) and (xb, yb) */
void line DDA(int xa, int ya, int xb, int yb) {
           
            int dx=xb-xa; // horizontal difference
            int dy=yb-ya; // vertical difference
            int steps, k;
            float xIncrement, yIncrement;
            float x=xa, y=ya; // the drawing points x and y are initiated to one endpoint of the line

            // calculate the number of steps used to draw the line (number of pixels)
            if(abs(dx)>abs(dy)) 
                steps=abs(dx);
            else 
                steps=abs(dy);        

            // calculate the increment for x and y in each step
            xIncrement=dx/(float)steps;
            yIncrement=dy/(float)steps;

            // point out the starting pixel
            setPixel(ROUND(x), ROUND(y));

            // loop through the line from one end to the other and point out the pixels
            for(k=0; k<steps; k++) {
                    
                    // the points are incremented an equal amount for every step
                    x += xIncrement;
                    y += yIncrement;
                        
                    // since the values for x and y are float they are rounded before they are plotted
                    setPixel(ROUND(x), ROUND(y));
            }
}

[edit] See also

[edit] External links


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -