Complete Line Drawing Algorithms
Complete Line Drawing Algorithms
• Requirements:
• - Lines must appear straight.
• - Lines should start and end accurately.
• - Maintain constant brightness along their
Line Drawing Algorithms
• Using the Cartesian slope-intercept equation:
• - m = (y2 - y1) / (x2 - x1)
• - c = y1 - m * x1
• Algorithm Steps:
• 1. Input two line endpoints: (xa, ya) and (xb,
yb).
• 2. Calculate dx = xb - xa and dy = yb - ya.
• 3. Calculate the length: Length = max(|dx|, |
dy|).
DDA Algorithm Steps (Continued)
• 5. Initialize:
• x = xa, y = ya
• i=1
• 6. While i <= length:
• - Plot the pixel (round(x), round(y))
• - Increment:
• x = x + Δx
• y = y + Δy
• i=i+1
DDA Algorithm Example
• Example: Line from (2,3) to (6,6)
• Calculations:
• - 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.
• - Efficiently determines the pixel closest to the
line.
• Steps:
• - Move across the x-axis in unit intervals.
• - At each step, choose between two y-
coordinates.
Bresenham's Algorithm Example
• Example: Line from (2,3)
• At each step, determine:
• - Whether to plot (x + 1, y) or (x + 1, y + 1).