1 / 30

Mid Point Line Drawing Algorithm

Mid Point Line Drawing Algorithm. Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Computer Graphics Course Kocaeli University Fall 2013. How to Improve It?. Question: if we draw the current pixel, where is the next pixel? Next column, E or NE direction.

mei
Télécharger la présentation

Mid Point Line Drawing Algorithm

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. Mid Point Line Drawing Algorithm Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Computer Graphics Course Kocaeli University Fall 2013

  2. How to Improve It? Question: if we draw the current pixel, where is the next pixel? Next column, E or NE direction

  3. Midpoint Algorithm • Given a point just drawn, determine whether we move E or NE on next step • Is the line above or below ? Below: move E Above: move NE

  4. Above/Below the Line?

  5. Two Issues • How to evaluate if the midpoint is above or below the line? • How to incrementally evaluate this?

  6. Midpoint Algorithm – Implicit Forms • How do we tell if a point is above or below the line?

  7. Midpoint Algorithm – Implicit Forms • How do we tell if a point is above or below the line?

  8. Midpoint Algorithm – Implicit Forms • How do we tell if a point is above or below the line? Properties f(x,y)=0 (x,y) on the line f(x,y)<0 (x,y) below the line f(x,y)>0 (x,y) above the line

  9. Midpoint Algorithm – Implicit Forms

  10. Two Issues • How to evaluate if the midpoint is above or below the line? • How to incrementally evaluate this? What about starting value? What is the middle point? (xL+1,yL+1/2)

  11. Midpoint Algorithm What about starting value? (xL+1,yL+1/2) is on the line!

  12. Midpoint Algorithm What about starting value? Multiplying coefficients by 2 doesn’t change sign of f

  13. Midpoint Algorithm • Need value of to determine E or NE • Build incremental algorithm • Assume we have value of • Find value of if E chosen

  14. Midpoint Algorithm Need value of to determine E or NE Build incremental algorithm Assume we have value of Find value of if E chosen Find value of if NE chosen 14/110

  15. Midpoint Algorithm If E was chosen, find

  16. Midpoint Algorithm If NE was chosen, find

  17. Midpoint Algorithm – Summary x=xLy=yL d=xH - xL c=yL - yH sum=2c+d //initial value draw(x,y) while ( x < xH) // iterate until reaching the end point if ( sum < 0 ) // below the line and choose NE sum+= 2d y++ x++ sum += 2c draw(x,y)

  18. Midpoint Algorithm – Summary x=xLy=yL d=xH - xL c=yL - yH sum=2c+d //initial value draw(x,y) while ( x < xH) // iterate until reaching the end point if ( sum < 0 ) // below the line and choose NE sum+= 2d y++ x++ sum += 2c draw(x,y) - Update the current pixel - Update the function value of midpoint 18/110

  19. Midpoint Algorithm – Summary x=xLy=yL d=xH - xL c=yL - yH sum=2c+d //initial value draw(x,y) while ( x < xH) // iterate until reaching the end point if ( sum < 0 ) // below the line and choose NE sum+= 2d y++ x++ sum += 2c draw(x,y) - Draw the pixel based on the function value of midpoint 19/110

  20. Midpoint Algorithm – Example x=xLy=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum+= 2d y++ x++ sum += 2c draw(x,y) d =6 c = -2

  21. Midpoint Algorithm – Example x=xLy=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum+= 2d y++ x++ sum += 2c draw(x,y) d =6 c = -2

  22. Midpoint Algorithm – Example x=xLy=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum+= 2d y++ x++ sum += 2c draw(x,y) d =6 c = -2

  23. Midpoint Algorithm – Example x=xLy=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum+= 2d y++ x++ sum += 2c draw(x,y) d =6 c = -2

  24. Midpoint Algorithm – Example x=xLy=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum+= 2d y++ x++ sum += 2c draw(x,y) d =6 c = -2

  25. Midpoint Algorithm – Example x=xLy=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum+= 2d y++ x++ sum += 2c draw(x,y) d =6 c = -2

  26. Midpoint Algorithm – Example x=xLy=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum+= 2d y++ x++ sum += 2c draw(x,y) d =6 c = -2

  27. Midpoint Algorithm – Example x=xLy=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum+= 2d y++ x++ sum += 2c draw(x,y) d =6 c = -2

  28. Midpoint Algorithm • Only integer operations • Exactly the same as the more commonly found Bresenham’s line drawing algorithm • Extends to other types of shapes (circles)

  29. Midpoint Algorithm – Example x=xmin y=ymin d=xmax- xmin c=ymin- ymax sum=2c+d draw(x,y) while ( x < xmax) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

  30. Midpoint Algorithm – Example x=xmin y=ymin d=xmax- xmin c=ymin- ymax sum=2c+d draw(x,y) while ( x < xmax) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

More Related