CHAPTER IV: Computer Graphics
• In order to display any object on a computer
screen, the most important information is
which pixel has to be highlighted for
accomplishing it.
• Most human operators think in terms of
complex graphic objects such as cubes, cones,
circles, and ellipses. Representing continuous
graphics objects as a collection of discrete
pixels is known as scan conversion.
Geometry and Line Generation
• Several line drawing algorithms are
developed:
• - Their objective is to enable visually
satisfactory images in the least possible time.
• - Achieved by reducing calculations using
integer arithmetic instead of floating-point
arithmetic.
• The computer screen is divided into rows and
columns. The intersection of these rows and
General Requirements for Drawing
a Line
• To draw a line on the screen:
• - Determine which pixels need to be switched
ON to approximate the desired line.
• - The process is known as rasterization.
• 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
• Algorithms for displaying straight lines are
based on:
• 1. Δy = m * Δx
• 2. Δx = Δy / m
DDA (Digital Differential Analyzer)
Algorithm
• DDA is a scan-conversion line algorithm based
on Δx or Δy.
• 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).
• The decision depends on which pixel is closer
to the actual line.