100% found this document useful (1 vote)
471 views

DDA Line Drawing Algorithm

The document discusses algorithms for drawing lines on a raster display. It describes determining the pixels that should be turned on to represent a line between two points. Methods include calculating the slope of the line and using that slope to determine the change in y-values over increments of x. The digital differential analyzer algorithm samples the line at integer x-values and rounds the corresponding y-values to the nearest pixels. Considerations for lines with negative slope or slope greater than one are also discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
471 views

DDA Line Drawing Algorithm

The document discusses algorithms for drawing lines on a raster display. It describes determining the pixels that should be turned on to represent a line between two points. Methods include calculating the slope of the line and using that slope to determine the change in y-values over increments of x. The digital differential analyzer algorithm samples the line at integer x-values and rounds the corresponding y-values to the nearest pixels. Considerations for lines with negative slope or slope greater than one are also discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

WHERE TO DRAW A LINE??

 Line drawing is accomplished by calculating


intermediate positions along the line path between
specified end points.
 Precise definition of line drawing
Given two points P and Q in the plane, both
with integer coordinates, determine which
pixels on a raster screen should be on in order
to make a picture of a unit-width line segment
starting from P and ending at Q.
6 (3, 3)
5
4
3
2
1
0
0 1 2 3 4 5 6
Line drawing (cont)
 The thinnest line is of one-pixel wide. We will
concentrate on drawing a line of 1 pixel resolution.
 The Cartesian slope-intercept equation for a straight

line is
y= m. x + b
m is the slope of the line and b is the y intercept.
Given the endpoints of a line segment.
m = y2-y1 / x2-x1
b= y1-m.x1
Line Drawing (cont)
 Also for any given interval ∆x along a line, we can
compute the corresponding y interval ∆y from
∆y= m. x
 Similarly we can obtain the x interval ∆x
corresponding to a specified ∆y as
∆x= ∆y / m
 These equations form the basis for determining
deflection voltages in analog devices.
Line Drawing (cont)
 Also , for any given x interval ∆x along a line, we
can compute the corresponding y interval ∆y from
∆y= m. ∆ x
 These equations form the basis for determining
deflection voltages in analog devices.
 On Raster systems, lines are plotted with pixels,
and step sizes in the horizontal and vertical
directions are constrained by pixel separations.
Hence we ought to “sample” a line at discrete
positions and determine the nearest pixel to the line
at each sampled position.
Symmetry
 If we could draw lines with positive slope (0<=slope<=1) we
would be done.
 For a line with negative slope (0>=slope>=-1)

We negate all Y values


 For a line with slope > 1 or slope <-1

we just swap x and y axes


(-y,x) (y,x)

(x,-y) (x,y)
450

(-x,-y) (x,-y)

(-y,-x) (y,-x)
Code for drawing a line
……….

Invert_y_draw(int x,int y) If(0 <= slope <= 1)

draw_pixel(x,-y) draw_fn= draw_pixel


draw_lne(Px, PY, QX, QY, draw_fn)

Swap_xy_draw(int x,int y) Else if (-1 <= slope <= 0)

draw_fn = invert_y_draw
draw_pixel(y,x) Draw_line(PX, -PY, QX, -QY, draw_fn)

Else if (1 < slope)


Swap_xy_invert_y_draw(int x,int y)
draw_fn= swap_xy_draw
Draw_line(PY,PX,QY,QX)
draw_pixel(y,-x) Else
Draw_fn=swap_xy_invert_y_draw
Draw_line(-PY,PX,QY,-QX, draw_fn)
DDA ALGORITHM
 The digital differential analyzer (DDA) samples the line at unit
intervals in one coordinate corresponding integer values nearest
the line path of the other coordinate.

 The following is thus the basic incremental scan-


conversion(DDA) algorithm for line drawing
for x from x0 to x1
Compute y=mx+b
Draw_fn(x, round(y))
 Major deficiency in the above approach :
 Uses floats

 Has rounding operations


DDA Illustration

Desired Line
(xi+1, Round(yj+m))

(xi, yj)
(xi+1, yj+m)

(xi, Round(yj))

y2

y1

x1 x2

You might also like