CS 5500 Computer Graphics May 3 2007 CS

  • Slides: 11
Download presentation
CS 5500 Computer Graphics May 3, 2007 CS 5500 Computer Graphics © Chun-Fa Chang,

CS 5500 Computer Graphics May 3, 2007 CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

Today’s Topic • Bresenham’s line drawing algorithm. • Reference: Edward Angel’s book: – 4

Today’s Topic • Bresenham’s line drawing algorithm. • Reference: Edward Angel’s book: – 4 th Ed. Sections 7. 8 and 7. 9 – 3 rd Ed. Sections 8. 9 and 8. 10. CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

Scan Conversion • Also called rasterization. • The 3 D to 2 D Projection

Scan Conversion • Also called rasterization. • The 3 D to 2 D Projection gives us 2 D vertices (points). • We need to fill in the interior. CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

Line Drawing • Assuming: – Clipped (to fall within the window) – 2 D

Line Drawing • Assuming: – Clipped (to fall within the window) – 2 D screen coordinates – Each pixel covers a square region • where is its center? • Rounding (X, Y) implies center at (0. 0, 0. 0). • Truncating implies center at (0. 5, 0. 5). CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

DDA Algorithm • DDA stands for digital differential analyzer. • The differential equation for

DDA Algorithm • DDA stands for digital differential analyzer. • The differential equation for a line is: m = dy / dx CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

Stepping in X direction CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

Stepping in X direction CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

Bresenham’s Algorithm • Improve upon DDA algorithm to use integer arithmetic only. • Applicable

Bresenham’s Algorithm • Improve upon DDA algorithm to use integer arithmetic only. • Applicable to circle drawing too. We discuss only the line drawing here. CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

Decision Variables • Variables a and b record the distances to the pixel centers

Decision Variables • Variables a and b record the distances to the pixel centers of (i+1, j) and (i+1, j+1) • If a > b, then y=j • If a < b, then y= j+1 CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

Integer Only • If (x 1, y 1) and (x 2, y 2) are

Integer Only • If (x 1, y 1) and (x 2, y 2) are integer points, then x * a and x * b may be stored as integers as well. – Because a and b increase or decrease by m = y / x CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007

Using the Symmetry • The above works when x 0, y 0, and x

Using the Symmetry • The above works when x 0, y 0, and x y. • If x < y, then step in Y direction instead. • It is easy to extend it to handle x < 0 or y < 0. CS 5500 Computer Graphics © Chun-Fa Chang, Spring 2007