Attribution Non-Commercial (BY-NC)

301 views

Attribution Non-Commercial (BY-NC)

- CMSC 405 Homework 4
- Sweep and Prune
- Processing for Visual Artists- How to Create Expressive Images and Interactive Art.pdf
- Assig 1 Quests
- Sanjay Ghemawat - Research at Google
- 992DW01 Data Warehousing
- Assembly Program's File
- Mind Mapping for Efficient PM
- Changepwd.java
- Ace Result Review - OTS Edc
- 03 RMS Frequency Planning Method
- 9900V 21-14-52
- Zone Alarm APC and Behavioral Based Analysis Bypass
- Hd Clone
- FALLSEM2016-17_MEE307_ETH_2506_22-SEP-2016_RM001_13 APT
- 408046280-220031593-LTE-Handover-Parameters.xlsx
- Instructions for Initiators in PRweb
- Trinity Core Custom Script
- D3Debug
- 17.04.435_dp

You are on page 1of 13

University of Cantabria

UC-CAGD Group

COMPUTER-AIDED GEOMETRIC DESIGN

AND COMPUTER GRAPHICS:

Andrés Iglesias

e-mail: iglesias@unican.es

Web pages: http://personales.unican.es/iglesias

http://etsiso2.macc.unican.es/~cagd

Line Drawing Algorithms

appear continuous made of pixels

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

Line Drawing Algorithms

We are going to analyze how this process is achieved.

Some useful definitions General requirements

Rasterization: Process of • Straight lines must appear as straight

determining which pixels lines.

provide the best approximation

to a desired line on the screen.

?

? ?

?

• They must start and end accurately

Scan Conversion: Combination • Lines should have constant brightness

of rasterization and generating the along their length

picture in scan line order. •Lines should drawn rapidly

Line Drawing Algorithms

For horizontal, vertical and For any other orientation the choice

45º lines, the choice of is more difficult:

raster elements is obvious.

This lines exhibit constant

brightness along the length:

?

? ?

?

?

? ?

?

Line Drawing Algorithms

Rasterization of straight lines.

? or

? ?

?

appear brighter than the 45º lines.

Compromise:

For fixing so, we would need:

1. Calculation of square roots 1. Calculate only an approximate line

(increasing CPU time) => 2. Use integer arithmetic

2. Multiple brigthness levels 3. Use incremental methods

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

Line Drawing Algorithms

The equation of a straight line is given by: y=m.x+b

1. Start at the pixel for the left-hand x = xl;

endpoint x1

while (x <= xr){

2. Step along the pixels horizontally

until we reach the right-hand end ytrue = m*x + b;

of the line, xr y = Round (ytrue);

PlotPixel (x, y);

3. For each pixel compute the

/* Set the pixel at (x,y) on */

corresponding y value x = x + 1;

4. round this value to the nearest

integer to select the nearest pixel }

This method therefore requires an enormous number of floating-point

multiplications, and is therefore expensive.

Line Drawing Algorithms

Algorithm 2: Digital Differential Analyzer (DDA)

The differential equation of a straight line is given by:

dy = constant ∆ y y2 - y1

or =

dx ∆x x2 - x1

The solution of the finite difference approximation is:

repeated

y2 - y1 addition

yi+1 = yi + ∆y

x2 - x1 1

1

The DDA algorithm runs rather slowly because it requires real

arithmetic (floating-point operations).

Line Drawing Algorithms

DDA algorithm for lines with -1 < m < 1 Example: Third quadrant

x = xl; -8 -7 -6 -5 -4 -3 -2 -1 0

0

ytrue = yl;

while (x <= xr){ -1

ytrue = ytrue + m; -2

y = Round (ytrue);

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

x = x + 1;

-4

}

Switching the roles of x and y when m>1

Gaps occur of x and y using

when m > 1 a unit step in y,

and 1/m for x.

Line Drawing Algorithms

Algorithm 3: Bresenham’s algorithm (1965)

Bresenham, J.E. Algorithm for computer control of a digital plotter, IBM Systems Journal,

January 1965, pp. 25-30.

This algorithm uses only integer arithmetic, and runs significantly faster.

Y

(1,1) Key idea: distance between

(0,1) ? the actual line and the nearest

1/2 ≤ m ≤ 1 grid locations (error).

Plot (1,1) Initialize error:

1/2 e=-1/2

e=e+m

Plot (1,0)

? X

Reinitialize error:

(0,0) (1,0) when e>0

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

Line Drawing Algorithms

Example: m=3/8

If e<0 below

below below above above

else above

Error

0

Reinitialize

error:

e = 1/4 -1

= -3/4

Error: e=e+m

Initial value: e = -1/2+3/8 e = -1/8+3/8 e = -3/4+3/8

e = - 1/2 =-1/8 = 1/4 = -3/8

Line Drawing Algorithms

However, this algorithm does not lead to integer arithmetic. Scaling by: 2* dx

void Bresenham (int xl, int yl, int xr, int yr)

{

int x,y; /* coordinates of pixel being drawn */

int dy, dx;

int ne; /* integer scaled error term */

x = xl; y = yl; /* start at left endpoint */

ie = 2 * dy - dx; /* initialize the error term */

while (x <= xr){ /* pixel-drawing loop */

PlotPixel (x,y); /* draw the pixel */

if (ie > 0) {

y = y + 1;

ne = ne - 2 * dx; /* replaces e = e - 1 */

}

x = x + 1;

ne = ne + 2 * dy; /* replaces e = e + m */

}

}

Line Drawing Algorithms

Bresenham’s algorithm also applies for circles.

Bresenham, J.E. A linear algorithm for incremental digital display of circular arcs

Communications of the ACM, Vol. 20, pp. 100-106, 1977.

the initial octant only

( 0 1

1 0 )

2 Reflect first octant about y=x

quadrant 2 octant

3

about x=0 1

( )

-1 0

0 1

4

4 Reflect upper

semicircle

about y=0

( )

1 0

0 -1

Line Drawing Algorithms

Bresenham’s incremental circle algorithm.

Example:

circle of radius 8 9

Bright pixels: 8

initial pixel (0,8)

7

(1,8)

(2,8) 6

(3,7)

5

(4,7)

(5,6) 4

(6,5)

3

(7,4)

(7,3) 2

(8,2) 1

(8,1)

0

end pixel (8,0) 0 1 2 3 4 5 6 7 8 9

- CMSC 405 Homework 4Uploaded byRichard Mcdaniel
- Sweep and PruneUploaded bysmokingrope__
- Processing for Visual Artists- How to Create Expressive Images and Interactive Art.pdfUploaded byRay Spender
- Assig 1 QuestsUploaded byPaul S
- Sanjay Ghemawat - Research at GoogleUploaded byShantanu Kallakuri
- 992DW01 Data WarehousingUploaded byisharepdf
- Assembly Program's FileUploaded byHirdesh
- Mind Mapping for Efficient PMUploaded bymagav1980
- Changepwd.javaUploaded byPrishan De Silva
- 03 RMS Frequency Planning MethodUploaded bysohappy2
- 9900V 21-14-52Uploaded byasdf
- FALLSEM2016-17_MEE307_ETH_2506_22-SEP-2016_RM001_13 APTUploaded byDeepak Dileep
- Ace Result Review - OTS EdcUploaded byAmit Verma
- Zone Alarm APC and Behavioral Based Analysis BypassUploaded bymacgyver
- 408046280-220031593-LTE-Handover-Parameters.xlsxUploaded bymohamed
- Trinity Core Custom ScriptUploaded byvalakiakarki
- Hd CloneUploaded byBlaze Copier
- Instructions for Initiators in PRwebUploaded byDavid Peterson
- D3DebugUploaded byTeletin Ciprian
- 17.04.435_dpUploaded byBagas Setiawan
- gameplaysmpseudocodeUploaded byapi-350941923
- Generic Delta Saftey IntervalsUploaded bysrikiran
- STA - Part 7Uploaded byHimanshu Gome
- Salesforce Report Summary Functions CheatsheetUploaded byMadhuri Malayathi
- MazeUploaded bySoubhik Biswas
- Embedded System (2) (1).docxUploaded byAkash
- Control Data SetupUploaded byDares Inc.
- ODEVDSP_2Uploaded bydawadhali
- A c++ gameUploaded byArko Roy
- 3 Mind MapUploaded bysamee

- memtechchennaibinder.pdfUploaded byelectricalconsultant
- 16 bit RISCUploaded byAli Ahmad
- distinguish between systems programs and application programsUploaded byapi-247871582
- Waterfall Project ScheduleUploaded bybidwx
- 國立交通大學單位中英文名稱對照表 - 國立交通大學秘書室Uploaded byEugene Lin
- ABOUT ASSEMBLERS_ ASSEMBLER ALGORITHM AND DATA STRUCTURES.pdfUploaded byrituraj69
- CMP 477 Computer Graphics Module 1Uploaded byblessing edu
- SIMD ArchitectureUploaded bybinzidd007
- Compilers Programming EmbeddedUploaded byjagadeshneo
- KnowledgeRepresentationIssues.pdfUploaded byAbhinav Shrivastava
- unix_wUploaded byn.rajesh
- RQST-BRET-20091022-PAE32_newUploaded byAlexandru Manea
- 07 C ProgrammingUploaded bySubramanian Venkatesan
- A Survey on the Foundation of Software ArchitectureUploaded byGRD Journals
- Redbooks - C ZOSUploaded byRodrigo De Oliveira Gonzalez
- ARM_PROCESSORUploaded byKarrthik Mhatrre
- Computational GeometryUploaded byZvonko Trzun
- UT Dallas Syllabus for cs6398.501.08s taught by Yuke Wang (yuke)Uploaded byUT Dallas Provost's Technology Group
- Leonard Adleman et al- Combinatorial Optimization Problems in Self-AssemblyUploaded byGmso3
- ThugLife.docxUploaded byAn Ne
- A Genetic Algorithm Based Approach for Test Data a Genetic Algorithm Based Approach for Test DataUploaded byharman28051989
- Basic Software Engineering Viva MaterialUploaded bydReaMsaLLAroUNd
- Aamc Minimum CompetenciesUploaded byAlvin Marcelo
- rr411Uploaded bysaurav_68
- Computes Science - HarvardUploaded byVictor Mts
- (Current Issues in Linguistic Theory 32) James E. Copeland-New Directions in Linguistics and Semiotics-Rice University Studies (1984)Uploaded bymasthozheng
- question number 1Uploaded bySteve Mus
- Vliw Architecture StudyUploaded byAbuturab Mohammadi
- Airline Reservation 1-1Uploaded bySahil Gupta
- Introduction to PIC 16C74X MicrocontrollerUploaded byArul Selvam