1 / 13

Chapter 3 Scan Conversion Lecture-02

Chapter 3 Scan Conversion Lecture-02. Bresenham’s Line Algorithm. Bresenham’s line algorithm is a highly efficient incremental method for scan-converting lines.

lucita
Download Presentation

Chapter 3 Scan Conversion Lecture-02

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 3Scan ConversionLecture-02

  2. Bresenham’s Line Algorithm • Bresenham’s line algorithm • is a highly efficient incremental method for scan-converting lines. • It produces mathematically accurate results using only integer addition, subtraction and multiplication by 2, which can be accomplished by a simple arithmetic shift operation.

  3. Bresenham’s Line Algorithm • Scan convert the line in the Figure, • 0<m<1. • Start with pixel P1(x1,y1). • Choose either the pixel on the right or the pixel right and up. • The coordinates of the last chosen pixel upon entering step i are (xi,yi). • Choose the next between the bottom pixel S and the top pixel T. p2 p1

  4. Bresenham’s Line Algorithm • The difference is – s – t = (y-yi)-[(yi+1)-y] = y-yi-yi-1+y = 2y-2yi-1 = 2(y-yi)-1 = 2 [ { m(xi + 1) + b } - yi) ] - 1 = 2 m(xi + 1) + 2b - 2yi– 1 ∆x( s – t)=∆x [2m(xi + 1) + 2b - 2yi – 1] So di = ∆x [2m(xi + 1) + 2b - 2yi – 1] ……………. (i) • If the chosen pixel is the top pixel T (di ≥ 0) then xi+1 = xi+1 and yi+1 = yi+ 1 and so di+1= di + 2 (Δy - Δx)

  5. Bresenham’s Line Algorithm • If the chosen pixel is pixel S (di < 0) then xi+1= xi+1 and yi+1 = yi and so • di+1 = di + 2Δy • where di = 2Δy * xi - 2Δx * yi +C • and C = 2Δy + Δx (2b – 1) • We use here a decision variable di . For the value of each di we calculate the corresponding value of di+1 . p2 p1

  6. Bresenham’s Line Algorithm • Hence, we have • Finally, we calculate d1 ,the base case value for this recursive formula, from the original definition of the decision variable di • di = ∆x [ 2m (x1 + 1) + 2b - 2y1 – 1] = ∆x [ 2( mx1 + b - y1 ) + 2m – 1] = ∆x [ 2*0 + 2m – 1] = 2(∆y/ ∆x)* ∆x- ∆x =2∆y- ∆x

  7. Bresenham’s Line Algorithm • Line 10: if(d<0) • Line 11: { • Line 12: d=d+dS; • Line 13: putpixel(x1,y1); • Line 14: } • Line 15: else • Line 16: { • Line 17: y1++; • Line 18: d=d+dT; • Line 19: putpixel(x1,y1); • Line 20: } • Line 21: } • Line 22: putpixel(x2,y2); • } • Void Bresenham( ) • { • Line 1: dx=x2-x1; • Line 2: dy=y2-y1; • Line 3: dT=2*(dy-dx); • Line 4: dS=2*dy; • Line 5: d=(2*dy)-dx; • Line 6: putpixel(x1,y1); • Line 7: while(x1<x2) • Line 8: { • Line 9: x1++;

  8. Scan-Converting a Circle

  9. P=(xp, yp) E yp ME M yp – 1 SE MSE yp – 2 xp xp+1 xp+2 Next Current Previous Midpoint Circle Algorithm • Implicit of equation of circle is: x2 + y2 - R2 = 0 • Eight way symmetry  require to calculate one octant • Define decision variable d as:

  10. P=(xp, yp) E yp ME d < 0 M yp – 1 yp – 2 xp xp+1 xp+2 Next Current Previous Midpoint Circle Algorithm • If d <= 0 then midpoint m is inside circle • we choose E • Increment x • y remains unchanged

  11. P=(xp, yp) yp M d > 0 yp – 1 SE MSE yp – 2 xp xp+1 xp+2 Next Current Midpoint Circle Algorithm • If d > 0 then midpoint m is outside circle • we choose S • Increment x • Decrement y Previous

  12. Midpoint Circle Algorithm Initial condition • Starting pixel (0, R) • Next Midpoint lies at (1, R – ½) • d0 = F(1, R – ½) = 1 + (R2 – R + ¼) – R2 = 5/4 – R • To remove the fractional value 5/4 : • d0= 1– R

  13. Midpoint Circle Algorithm • We can now summarize the algorithm for generating all the pixel coordinates in the 900 to 450 octant : Line 1 : Int x=0,y=r,p=1-r; Line 2 : While(x<=y) Line 3 : { Line 4 : setPixel(x,y); Line 5 : If(p<0) Line 6 : p=p+2x+3; Line 7 : Else Line 8 : { Line 9 : P=p+2(x-y)+5; Line 10 : y--; Line 11 : } Line 12 : x++; Line 1 3: }

More Related