0% found this document useful (0 votes)
19 views20 pages

Lecture 3 DDA

The document discusses line drawing algorithms in 2D graphics, focusing on the Digital Differential Analyzer (DDA) algorithm for rendering lines based on the Cartesian slope-intercept equation. It explains how to sample points along a line at unit intervals and compute the corresponding pixel positions, addressing challenges such as anti-aliasing and efficiency. The document also highlights the need for integer arithmetic to simplify the implementation of the DDA algorithm in hardware.

Uploaded by

klubk192
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views20 pages

Lecture 3 DDA

The document discusses line drawing algorithms in 2D graphics, focusing on the Digital Differential Analyzer (DDA) algorithm for rendering lines based on the Cartesian slope-intercept equation. It explains how to sample points along a line at unit intervals and compute the corresponding pixel positions, addressing challenges such as anti-aliasing and efficiency. The document also highlights the need for integer arithmetic to simplify the implementation of the DDA algorithm in hardware.

Uploaded by

klubk192
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Lecture 3

Line - Drawing Algorithms


DDA

1
2D Graphics Primitives
2D Graphics Primitives
• Graphics drawing is based on basic geometric
structures called graphics primitives
• Points
• Lines
• Circles
• Conic Sections
Towards the Ideal Line
• We can only do a discrete approximation

• Illuminate pixels as close to the true path as possible,


consider bi-level display only
• Pixels are either lit or not lit
• In the raster line alg.,
• we sample at unit intervals and
• determine the closest pixel position to the specified line
path at each step
What is an ideal line
• Must appear straight and continuous
• Only possible with axis-aligned and 45 o lines
• Must interpolate both defining end points
• Must have uniform density and intensity
• Consistent within a line and over all lines
• What about anti-aliasing ?
• Aliasing is the jagged edges on curves and diagonal lines in a bitmap
image.
• Anti-aliasing is the process of smoothing out those jaggies.
• Graphics software programs have options for anti-aliasing text and graphics.
• Enlarging a bitmap image accentuates the effect of aliasing.

• Must be efficient, drawn quickly


• Lots of them are required
Simple Line

The Cartesian slope-intercept


equation for a straight line is :
y = mx + b
with m as the slope of the line
and b as the y intercept.
Simple approach:
• increment x, solve for y
Drawing Lines
 Drawing a line between two pixels [x0, y0]T and [x1, y1]T is
done by
intensifying (or turning on) pixels along the path of this
line.

The blue pixels are


not exactly on the
line path!

Note that this line


has a slope <1.
(c) 2023, Dr. R. Elias 2D Graphics Why? 7
Simple Line

Based on slope-intercept
algorithm from algebra:
y = mx + b
Simple approach:
increment x, solve for y
Floating point arithmetic
required
Algorithms for displaying lines are based on the Cartesian slope-
intercept equation
y = m.x + b
where m and b can be calculated from the line endpoints:
m = (y1-y0) / (x1-x0)
b = y0 - m. x0

For any x interval x along a line the corresponding y interval y =


m.x

y1

y0

x0 x1
Does it Work?
It works for lines with a slope of 1 or
less,
but doesn’t work well for lines with slope
greater than 1 – lines become more
discontinuous in appearance and we must
add more than 1 pixel per column to
make it work.
Solution? - use symmetry.
Modify algorithm per octant

OR, increment along x-axis if dy<dx else increment along


y-axis
DDA Algorithm
• The digital differential analyser (DDA) is a scan-conversion line algorithm
based on using x or y.

• A line is sampled at unit intervals in one coordinate and the corresponding


integer values nearest the line path are determined for the other coordinate.
Line with positive slope
• If m<=1,
• Sample at unit x intervals (dx=1)
• Compute successive y values as
• yk+1=yk+m 0<=k<=xend-x0
• Increment k by 1 for each step
• Round y to nearest integer value.

• If m>1,
• Sample at unit y intervals (dy=1)
• Compute successive x values as
• xk+1=xk+1/m 0<=k<=yend-y0
• Increment k by 1 for each step
• Round x to nearest integer value.
inline int round (const float a) { return int (a + 0.5); }

void lineDDA (int x0, int y0, int xEnd, int yEnd)
{
int dx = xEnd - x0, dy = yEnd - y0, steps, k;
float xIncrement, yIncrement, x = x0, y = y0;

if (fabs (dx) > fabs (dy))


steps = fabs (dx);
else
steps = fabs (dy);
xIncrement = float (dx) / float (steps);
yIncrement = float (dy) / float (steps);

setPixel (round (x), round (y));


for (k = 0; k < steps; k++) {
x += xIncrement;
y += yIncrement;
setPixel (round (x), round (y));
}
}
Using DDA, Draw a line
:from (1,1) to (8,7)
• Input endpoints: (𝑥1,𝑦1)=(1,1), (𝑥2,𝑦2)=(8,7)
• Calculate differences:Δ𝑥=𝑥2−𝑥1=8−1=7,Δ𝑦=𝑦2−𝑦1=7−1=6
• Determine the number of

• increments:𝑥inc=Δ𝑥 Steps=77=1, 𝑦inc=Δ𝑦


Steps=max⁡(∣Δ𝑥∣,∣Δ𝑦∣)=max⁡(7,6)=7

• Initialize starting point:𝑥=𝑥1=1,𝑦=𝑦1=1


Steps=67≈0.857

• Iterate for the number of steps:


At each step, add 𝑥inc​ to 𝑥 and 𝑦inc to 𝑦, rounding to
thenearest pixel.
Using DDA, Draw a line from
:(0,0) to (4,6)
Using DDA, Draw a line
:from (2,3) to (9,8)
DDA Modification
DDA algorithm
• Need a lot of floating point arithmetic.
– 2 ‘round’s and 2 adds per pixel.

• Is there a simpler way ?


• Can we use only integer arithmetic ?
– Easier to implement in hardware.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy