Docsity

Bresenham’s Line Algorithm-Computer Graphics-Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Bresenham’s Line Algorithm-Computer Graphics-Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Computer Graphics

Line drawing can get complicated!

Bresenham’s Line Algorithm ^

Proposed by Bresenham that draws lines using onlyincremental integer calculations ^

Can be adapted for circles and curves

^

Sampling at unit x intervals we need to determinewhich pixel position is closer to the line path

^

This is determined by ^

Testing sign of an integer parameter to determinewhich pixel is closer tothe actual line path

NE M Q

P(x

, yp

)p^

E

Bresenham

’s Line Algorithm

^

Accurate and Efficient ^

Use only incremental integer calculations

^

Test the sign of an integer parameter

^

Case) Positive Slope Less Than 1 ^

After the pixel (

xk

,^ y

) is displayed,k

next which pixel is decided to plotin column

x

k+

xk

,^ y

) or (k

xk

,^ y

+1k

)^

xk

yk

xk

yk

Bresenham

’s Algorithm(cont.)

^

Case) Positive Slope Less Than 1

^

y^

at sampling position

x

k

^

Difference ^

Decision parameter

xk

yk

xk

yk

^

^

b

x m y^

k^

 

^

1 

^

k

k

k^

y b x m y y

d^

^

1

^

^

b x m y y y

d^

k

k

k^

^

2

d^1

-^

d^2

< 0

( x

+1,k

y

)k

d^1

-^

d^2

> 0

( x

+1,k

y

+1)k

^

^

 c y x x y b x y y x x y

d d x

p

k

k

k

k

k

2 1

d^2^ d^1

Bresenham

’s Algorithm(cont.)

^

Algorithm for 0<

m

<

^

Input the two line endpoints and store the left end point in (

x^0

,^ y

) 0

^

Load (

x,^0

y^0

) into the frame buffer; that is, plot the first point

^

Calculate constants

Δ

x,^

Δy

,^2

Δy

, and

2

Δy

−^

2 Δ

x, and obtain the

starting value for the decision parameter as ^

At each

x^ k

along the line, start at

k^

=

, perform the following test:

^

If^ p

< 0k^

, the next point to plot is (

x+1k

,^ y

) andk

^

Otherwise, the next point to plot is (

x+1k

,^ y

+1k

) and

^

Repeat step 4

Δ

x^ times

x

y

p^

^

0

y

p

p^

k

k^

^

1

x

y

p

p^

k

k^

^

1

Bresenham’s Line Drawing Algorithm ^

The above algorithm works for slopesbetween 0 and 1 ^

If slope is greater than 1, we interchange theroles of x and y directions as in DDA ^

We step along y and calculate successive xvalues nearest to the line path

^

Whenever there is a tie between candidatepixels, we make sure that the same policy isfollowed

Line Function ^

A function for line drawing may be available for a variety ofgraphical packages ^

OpenGL ^

PHIGS

^

They fundamentally use the same algorithms ^

DDA ^

Besenham’s algorithms

^

Relative coordinate specifications may be employed or absolute ^

Conversions may be made between modelling coordinates toworld coordinates to normalized coordinates to devicecoordinates ^

A line drawing may be divided into portions and each successivecall may draw parts of the line between two points