# CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.

## Presentation on theme: "CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007."— Presentation transcript:

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

CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 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.

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

CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 Line Drawing Assuming: –Clipped (to fall within the window) –2D 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).

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

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

CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007

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

CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 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

CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 Integer Only If (x1, y1) and (x2, y2) 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

CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 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.