bresenman

3
7/23/2019 bresenman http://slidepdf.com/reader/full/bresenman 1/3 It is an effici ent raster li ne generation algorithm. The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage of this algorithm is that, it uses only integer calculations. Moving across the x axis in unit intervals and at each step choose between two different y coordinates. For example, as shown in the following illustration, from position (2, 3) you need to choose between (3, 3) and (3, 4). You would like the point that is closer to the original line. Consider lines with positive slope For a positive slope, 0 < m < 1 and line is starting from left to right. (xk +1, yk) (xk +1, yk+1) After plotting a pixel position (xk, yk) we have two choices for next pixel: At position xk +1, we pay attention to the intersection of the vertical pixel and the mathematical line path.  Unfiled Notes Page 1

Upload: mohammad-saida

Post on 18-Feb-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: bresenman

7/23/2019 bresenman

http://slidepdf.com/reader/full/bresenman 1/3

It is an efficient raster line generation algorithm.The Bresenham algorithm is another incremental scan conversion algorithm.

The big advantage of this algorithm is that, it uses only integer calculations.Moving across the x axis in unit intervals and at each step choose between

two different y coordinates.For example, as shown in the following illustration, from posit ion (2, 3) you

need to choose between (3, 3) and (3, 4). You would like the point that iscloser to the original line.

Consider lines with positive slopeFor a positive slope, 0 < m < 1 and line is starting from left toright.

(xk +1, yk)(xk +1, yk+1)

After plotting a pixel position (xk, yk) we have two choices fornext pixel:

At position xk +1, we pay attention to the intersection of thevertical pixel and the mathematical line path.

 

Unfiled Notes Page 1

Page 2: bresenman

7/23/2019 bresenman

http://slidepdf.com/reader/full/bresenman 2/3

At position xk +1, we label vertical pixel separations from themathematical l ine path as

dlower , dupper.

y = m(xk +1)+ b

The y coordinate on the mathematical line at xk+1 is calculatedas

= m (xk +1) + b − yk

dlower = y − yk

then

= yk +1− m(xk +1)− bdupper =(yk +1)

−y

and

dlower - dupper = 2m (xk +1) − 2yk + 2b - 1

= 2 (Δy / Δx) (xk +1) − 2yk + 2b - 1

Let us substitute m with Δy/Δx where Δy and Δx are thedifferences between end points.

To determine which of the two pixels is closest to the line path,we set an efficient test based on the difference between the twopixel separations

= 2Δy.xk  − 2Δx.yk + cpk = Δx (dlower - dupper )Consider a decision parameter pk such that

wherec = 2Δy + Δx(2b −1)Since Δx > 0, Comparing (dlower and dupper ), would tell which pixelis closer to the line path; is it yk or yk + 1

Hence plot lower pixel.Then pk is negative

Plot the upper pixel.Otherwise

If (dlower < dupper )

We can obtain the values of successive decision parameter asfollows:

  Unfiled Notes Page 2

Page 3: bresenman

7/23/2019 bresenman

http://slidepdf.com/reader/full/bresenman 3/3

pk = 2Δy.xk  − 2Δx.yk + cpk+1=2Δy.xk+1−2Δx.yk+1+c

pk+1− pk = 2Δy (xk+1  − xk) − 2Δx ( yk+1  − yk)Subtracting these two equations

pk+1 = pk +2Δy − 2Δx (yk+1  − yk)But xk+1  − xk = 1, Therefore

( yk+1  − yk) is either 0 or 1, depending on the sign of pk (plottinglower or upper pixel).The recursive calculation of pk is performed at integer x position,starting at the left endpoint.

p0 can be evaluated as:p0 = 2Δy −  ΔxBresenham’s Line Drawing for m< 1Input the two line end points and store the left end point in ( x 0 ,y 0 ).

1.

Load ( x 0 , y 0 ) into the frame buffer; that is, plot the first point.2.

 p0 = 2Δy −  Δ x 

Calculate the constants Δ x , Δy , 2Δy , and 2Δy−

2Δ x , and obtainthe starting value for the decision parameter as

3.

 pk +1= pk +2Δy 

 pk +1= pk +2Δy −2Δ x 

Otherwise, the next point to plot is ( x k +1, y k +1) and

At each x k along the line, starting at k = 0 , perform the followingtest: If pk < 0,the next point to plot is ( x k +1, y k and

4.

5. Repeat step 4, Δ x −1 times.The constants 2Δy and 2Δy − 2Δ x are calculated once for eachline to be scan converted.Hence the arithmetic involves only integer addition andsubtraction of these two constants.

Unfiled Notes Page 3