You are on page 1of 2

DDA Algorithm

• Digital Differential Analyser / Basic Incremental Method

• Simplest strategy is to use the slope, m.

Figure 4: The change in the value of y with an increment in x in the first


• Step along the X-axis from to .

• For each value of calculate the value of and round to the nearest pixel.

•Calculation of can be performed incrementally as .


Substitute the two end-point coordinates and to obtain:

Use equation (2) to simplify equation (3) as

Code for DDA Algorithms

void line(int x0, int y0, int x1, int y1, int value)
int x;
float dy, dx, y, m;

dy = y1 - y0;
dx = x1 - x0;
m = dy / dx;
y = y0;

for( x = x0; x <= x1; x++ ) {

setPixel( x, (int) floor( y+0.5 ), value );
y += m;

Note: The floor(x) function returns the largest integer value less than or equal to x.
Also, y doesn't change according to what pixel is set, but according to m.
Drawbacks of DDA Algorithm
• Requires real (Floating Point) arithmetic which can be more expensive for HW
implementation (slower for historical reasons).
• Rounding off is an extra real operation.
• Long lines may suffer from round-off error in m.