Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9
Computer Graphics
Geometry and Line Generation -
Detailed Overview CHAPTER IV: Computer Graphics • In order to display any object on a computer screen, the most important information is which pixel needs to be highlighted for accomplishing it.
• Representing continuous graphic objects as
discrete pixels is called scan conversion. Line Drawing Algorithms • Several line drawing algorithms are developed: • - Minimize calculations by using integer arithmetic • - Divide the screen into rows and columns (pixels) • Equations used: • m = (y2 - y1) / (x2 - x1) • c = y1 - m * x1 Requirements for Drawing a Line • General requirements: • - Lines must appear to be straight • - Lines should start and end accurately • - Maintain constant brightness along the length • - Lines should be drawn rapidly • Cartesian equation: y = mx + c DDA Algorithm Overview • DDA (Digital Differential Analyzer) Algorithm: • - Based on Δx or Δy • - Provides the best pixel approximation for a straight line. • Steps: • 1. Input two endpoints (xa, ya) and (xb, yb) • 2. Compute dx, dy, and length DDA Algorithm Steps (Continued) • 3. Calculate Δx and Δy: • Δx = dx / length • Δy = dy / length • 4. Plot initial pixel (x, y) • 5. Increment and repeat for the entire length. DDA Algorithm Example • Example: Line from (2,3) to (6,6) • - dx = 4, dy = 3, Length = 4 • - Δx = 1, Δy = 0.75 • - Pixels plotted: (2,3), (3,3.75), (4,4.5), (5,5.25), (6,6) Bresenham's Line Algorithm • Incremental scan-conversion algorithm: • - Uses only integer calculations • - Efficient and avoids floating-point operations • - Determines the closest pixel to the line Bresenham Algorithm Example • For each x-step, choose between two y- coordinates • Example: Line from (2,3) • - Decision variables guide pixel plotting closer to the line.