Вы находитесь на странице: 1из 11

Efforts By :-

Abhishek Bhardwaj
(00290202015)
Contents

• Introduction
• DDA Line Algorithm
• DDA DrawBacks
Introdiction
In computer graphics, a digital differential analyzer (DDA) is hardware or
software used for interpolation of variables over an interval between start and
end point. DDAs are used for rasterization of lines, triangles and polygons.
They can be extended to non linear functions, such as perspective correct
texture mapping, quadratic curves, and traversing voxels.

In its simplest implementation for linear cases such as lines, the DDA algorithm
interpolates values in interval by computing for each xi the equations.
x(i) = x(i−1) + 1, yi = y(i−1) + m, where
Δx = x2(end) − x1(start) and Δy = y2(end) − y1(start) and m = Δy/Δx
Digital Differential Analyzer (DDA): Line
Drawing Algorithm
Walk through the line, starting at (x0,y0)

Constrain x, y increments to values in [0,1] range


(x1,y1)
Case a: x is incrementing faster (m < 1)
dy

(x0,y0) Step in x=1 increments, compute and round y


dx

Case b: y is incrementing faster (m > 1)

Step in y=1 increments, compute and round x


Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm which
is explained step by step here.

1) Step 1 − Get the input of two end points (X0,Y0)(X0,Y0) and (X1,Y1)(X1,Y1).

2) Step 2 − Calculate the difference between two end points.

dx = X1 - X0
dy = Y1 - Y0

3) Step 3 − Based on the calculated difference in step-2, you need to identify the number of
steps to put pixel. If dx > dy, then you need more steps in x coordinate; otherwise in y
coordinate.

if (absolute(dx) > absolute(dy))


Steps = absolute(dx);
else
Steps = absolute(dy);
Step 4 − Calculate the increment in x coordinate and y coordinate.

Xincrement = dx / (float) steps;

Yincrement = dy / (float) steps;

Step 5 − Put the pixel by successfully incrementing x and y coordinates accordingly and complete the
drawing of the line.

for(int v=0; v < Steps; v++)


{
x = x + Xincrement;
y = y + Yincrement;
putpixel(Round(x), Round(y));
}
x = x0 y = y0
y k 1  y k  m
Illuminate pixel (x, round(y))
(x1,y1)
x = x0 + 1 y = y0 + 1 * m

Illuminate pixel (x, round(y))

x=x+1 y=y+1*m

Illuminate pixel (x, round(y))

Until x == x1
(x0, y0)
1 x = x0 y = y0
x k 1  xk  (x1,y1)
m Illuminate pixel (round(x), y)

y = y0 + 1 x = x0 + 1 * 1/m

Illuminate pixel (round(x), y)

y=y+1 x = x + 1 /m

Illuminate pixel (round(x), y)

(x0,y0) Until y == y1
compute m;
if m < 1:
{
float y = y0; // initial value
for(int x = x0;x <= x1; x++, y += m)
setPixel(x, round(y));
}
else // m > 1
{
float x = x0; // initial value
for(int y = y0;y <= y1; y++, x += 1/m)
setPixel(round(x), y);
}
• Note: setPixel(x, y) writes current color into pixel in column x and row y in frame
buffer
• DDA is the simplest line drawing algorithm
– Not very efficient
– Round operation is expensive
• Optimized algorithms typically used.
– Integer DDA
– E.g.Bresenham algorithm (Hill, 10.4.1)
• Bresenham algorithm
– Incremental algorithm: current value uses previous value
– Integers only: avoid floating point arithmetic
– Several versions of algorithm: we’ll describe midpoint version of algorithm
THANK YOU

Вам также может понравиться