This action might not be possible to undo. Are you sure you want to continue?

BooksAudiobooksComicsSheet Music### Categories

### Categories

### Categories

Editors' Picks Books

Hand-picked favorites from

our editors

our editors

Editors' Picks Audiobooks

Hand-picked favorites from

our editors

our editors

Editors' Picks Comics

Hand-picked favorites from

our editors

our editors

Editors' Picks Sheet Music

Hand-picked favorites from

our editors

our editors

Top Books

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Audiobooks

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Comics

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Sheet Music

What's trending, bestsellers,

award-winners & more

award-winners & more

Welcome to Scribd! Start your free trial and access books, documents and more.Find out more

© 2001 Andrés Iglesias. See: http://personales.unican.es/iglesias

COMPUTER-AIDED GEOMETRIC DESIGN AND COMPUTER GRAPHICS:

**LINE DRAWING ALGORITHMS
**

Andrés Iglesias e-mail: iglesias@unican.es Web pages: http://personales.unican.es/iglesias http://etsiso2.macc.unican.es/~cagd

they are made of pixels © 2001 Andrés Iglesias. See: http://personales.unican.Line Drawing Algorithms The lines of this object appear continuous However.es/iglesias .

unican. lines.es/iglesias General requirements • Straight lines must appear as straight ? ? ? ? Scan Conversion: Combination of rasterization and generating the picture in scan line order. • They must start and end accurately • Lines should have constant brightness along their length •Lines should drawn rapidly . Some useful definitions Rasterization: Process of determining which pixels provide the best approximation to a desired line on the screen.Line Drawing Algorithms We are going to analyze how this process is achieved. See: http://personales. © 2001 Andrés Iglesias.

See: http://personales. vertical and 45º lines. This lines exhibit constant brightness along the length: © 2001 Andrés Iglesias.es/iglesias For any other orientation the choice is more difficult: ? ? ? ? ? ? ? ? . the choice of raster elements is obvious.Line Drawing Algorithms For horizontal.unican.

See: http://personales. we would need: 1. For fixing so. Multiple brigthness levels Compromise: => 1. Use incremental methods © 2001 Andrés Iglesias.Line Drawing Algorithms Rasterization of straight lines. ? ? ? ? or Rasterization yields uneven brightness: Horizontal and vertical lines appear brighter than the 45º lines. Calculate only an approximate line 2.es/iglesias . Use integer arithmetic 3.unican. Calculation of square roots (increasing CPU time) 2.

xr 3. The algorithm performs a floating-point multiplication for every step in x. © 2001 Andrés Iglesias. and is therefore expensive.unican. This method therefore requires an enormous number of floating-point multiplications. Start at the pixel for the left-hand endpoint x1 2.y) on */ x = x + 1. Step along the pixels horizontally until we reach the right-hand end of the line.es/iglesias while (x <= xr){ ytrue = m*x + b. See: http://personales. . For each pixel compute the corresponding y value 4. PlotPixel (x. round this value to the nearest integer to select the nearest pixel } x = xl.Line Drawing Algorithms The equation of a straight line is given by: y=m. y = Round (ytrue).x+b Algorithm 1: Direct Scan Conversion 1. /* Set the pixel at (x. y).

See: http://personales. as the start of the scan-conversion. ∆ y 1 DDA uses repeated addition .x1 1 We need only compute m once. The DDA algorithm runs rather slowly because it requires real arithmetic (floating-point operations).es/iglesias The solution of the finite difference approximation is: xi+1 = xi + ∆ x yi+1 = yi + y2 .unican.y1 ∆y dy = constant or = dx ∆x x2 .Line Drawing Algorithms Algorithm 2: Digital Differential Analyzer (DDA) The differential equation of a straight line is given by: y2 .x1 © 2001 Andrés Iglesias.y1 x2 .

es/iglesias Switching the roles of x and y when m>1 Reverse the roles of x and y using a unit step in y. x = x + 1. See: http://personales. while (x <= xr){ ytrue = ytrue + m. PlotPixel (x.Line Drawing Algorithms DDA algorithm for lines with -1 < m < 1 x = xl. y = Round (ytrue). Gaps occur when m > 1 . ytrue = yl.unican. y). and 1/m for x. } -8 -7 Example: Third quadrant -6 -5 -4 -3 -2 -1 0 0 -1 -2 -3 -4 © 2001 Andrés Iglesias.

Plot (1. January 1965.unican. pp. and runs significantly faster. Y (1.E.es/iglesias ? Key idea: distance between the actual line and the nearest 1/2 ≤ m ≤ 1 grid locations (error). This algorithm uses only integer arithmetic.Line Drawing Algorithms Algorithm 3: Bresenham’s algorithm (1965) Bresenham.1) 1/2 0 ≤ m ≤ 1/2 Plot (1. 25-30. IBM Systems Journal.1) © 2001 Andrés Iglesias.0) Initialize error: e=-1/2 Error is given by: e=e+m Reinitialize error: when e>0 ? (1. J.0) (0. Algorithm for computer control of a digital plotter. See: http://personales.1) (0.0) X .

See: http://personales.es/iglesias Line Drawing Algorithms Example: m=3/8 If e<0 below else above below Error 0 below above above Reinitialize error: e = 1/4 -1 = -3/4 Error: e=e+m Initial value: e = .1/2 e = -1/2+3/8 =-1/8 e = -1/8+3/8 = 1/4 e = -3/4+3/8 = -3/8 .unican.© 2001 Andrés Iglesias.

dx. int xr. /* replaces e = e .y. /* coordinates of pixel being drawn */ int dy.1 */ } x = x + 1.unican. ne = ne + 2 * dy. int yr) { int x.es/iglesias . /* integer scaled error term */ x = xl.y). this algorithm does not lead to integer arithmetic. dx. ne = ne . int yl.2 * dx. See: http://personales. y = yl. /* initialize the error term */ while (x <= xr){ /* pixel-drawing loop */ PlotPixel (x.Line Drawing Algorithms However. /* draw the pixel */ if (ie > 0) { y = y + 1. Scaling by: 2* dx void Bresenham (int xl. int ne. /* replaces e = e + m */ } } © 2001 Andrés Iglesias. /* start at left endpoint */ ie = 2 * dy .

1977. Vol.E. A linear algorithm for incremental digital display of circular arcs Communications of the ACM. 100-106. J.Line Drawing Algorithms Bresenham’s algorithm also applies for circles. Key idea: compute the initial octant only 0 1 1 0 2 Reflect first octant about y=x ( ) 3 Reflect first quadrant about x=0 -1 0 0 1 1 3 4 4 2 1 Generate first octant ( ) © 2001 Andrés Iglesias. pp. See: http://personales.es/iglesias Reflect upper semicircle about y=0 ( ) 1 0 0 -1 .unican. 20. Bresenham.

es/iglesias 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 .0) 9 8 © 2001 Andrés Iglesias.7) (4.2) (8.6) (6.8) (1.Line Drawing Algorithms Bresenham’s incremental circle algorithm.8) (3. See: http://personales.4) (7.unican.3) (8.7) (5. Example: circle of radius 8 Bright pixels: initial pixel (0.1) end pixel (8.8) (2.5) (7.

Dda Algorithm

Dda Algorithm

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue listening from where you left off, or restart the preview.

scribd