0% found this document useful (0 votes)
4 views

Unit 2 Computer Graphics

Uploaded by

Manan Khaldwa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Unit 2 Computer Graphics

Uploaded by

Manan Khaldwa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Raster Graphics Algorithms and

Transformations
This document explores fundamental raster graphics algorithms and transformations essential in computer graphics and
image processing. We'll cover line drawing algorithms like DDA and Bresenham's, circle and ellipse drawing techniques,
various filling algorithms, and both 2D and 3D transformations. These concepts form the foundation of digital image
creation and manipulation in modern computer graphics systems.
Line Drawing Algorithms: Digital Differential
Analyzer (DDA)
The Digital Differential Analyzer (DDA) algorithm is a simple yet effective method for rasterizing lines on digital displays.
It works by calculating intermediate points along the line path using floating-point arithmetic.
The DDA algorithm follows these steps:
1. Calculate the line slope and determine the longer axis (x or y).
2. Increment along the longer axis by 1 unit each step.
3. Calculate the corresponding position on the shorter axis using the slope.
4. Round the calculated values to the nearest integer for pixel placement.
While easy to implement, the DDA algorithm's reliance on floating-point calculations can lead to accumulated rounding
errors and slower performance compared to integer-based algorithms.
Line Drawing Algorithms: Bresenham's
Algorithm
Bresenham's line drawing algorithm, developed by Jack Bresenham in 1962, is a more efficient alternative to the DDA
algorithm. It uses only integer arithmetic, making it faster and more precise for rasterizing lines.
The algorithm works by making decisions about which pixels to plot based on the accumulated error term. For lines with
a slope between 0 and 1, it follows these steps:

1. Calculate initial error term and increments.


2. Plot the starting pixel.
3. For each step along the x-axis, decide whether to move straight or diagonally based on the error term.
4. Update the error term and repeat until the end point is reached.

Bresenham's algorithm can be adapted for lines with other slopes and even for drawing circles and ellipses.
Circle Drawing Algorithms
Circle drawing algorithms are crucial for creating circular shapes in raster graphics. The most common approach is the
midpoint circle algorithm, also known as Bresenham's circle algorithm. This algorithm leverages the circle's symmetry to
efficiently plot points.

The midpoint circle algorithm works by:

1. Starting at the top of the circle (0, radius).


2. Using a decision parameter to determine whether to plot the next pixel along or below the circle's arc.
3. Updating the decision parameter based on the chosen pixel.
4. Reflecting the plotted points in all octants of the circle.

This method only calculates points for one octant of the circle, significantly reducing computation time while maintaining
accuracy.
Ellipse Drawing Algorithms
Ellipse drawing algorithms extend the concepts used in circle drawing to handle the non-uniform radii of ellipses. The
midpoint ellipse algorithm is a common approach, similar to the midpoint circle algorithm but adapted for elliptical
shapes.
Key steps in the midpoint ellipse algorithm include:
1. Calculating initial decision parameters for both regions of the ellipse (more vertical and more horizontal sections).
2. Plotting points starting from (0, b) and (a, 0), where a and b are the semi-major and semi-minor axes.
3. Using decision parameters to choose the next pixel to plot.
4. Reflecting points in all four quadrants of the ellipse.

Optimizations can be made to reduce floating-point calculations and improve performance, especially for real-time
graphics applications.
Polygon Filling: Scan-Line Algorithm
1 Edge Table Creation
Create a table of all polygon edges, sorted by minimum y-coordinate.

2 Active Edge List Initialization


Start with the edges intersecting the first scan line.

3 Scan Line Processing


Fill between pairs of intersections, update active edges, and move to next scan line.

4 Edge Updates
Add new edges and remove completed edges as scanning progresses.

The scan-line polygon filling algorithm efficiently fills complex polygons by processing the shape one horizontal line at a
time. This method is particularly effective for handling concave polygons and those with holes.
Inside-Outside Tests and Boundary Fill
Inside-outside tests are crucial for determining whether a point lies within a polygon. Common methods include:

Ray casting: Count intersections of a ray from the point with polygon edges.
Winding number: Calculate the total angle formed by vectors from the point to polygon vertices.
Barycentric coordinates: Used for triangles, based on area ratios.

Boundary fill algorithms use these tests to fill shapes from a starting interior point. The algorithm recursively fills
neighboring pixels until it reaches the boundary color. This method is effective for simple shapes but can be inefficient
and prone to stack overflow for large areas.

Optimizations like span filling and non-recursive implementations can improve performance and reliability for boundary
fill operations.
Flood Fill and Area Fill Algorithms
Flood fill algorithms are used to fill connected regions of similar color in raster graphics. The basic flood fill algorithm
starts from a seed point and recursively fills adjacent pixels that meet a specified criterion (usually having the same color
as the starting point).
Two main approaches to flood fill are:
1. 4-connected: Fills only horizontally and vertically adjacent pixels.
2. 8-connected: Fills all adjacent pixels, including diagonals.

Area fill algorithms extend this concept to fill regions based on more complex criteria, such as texture patterns or color
ranges. These algorithms often employ techniques like pattern matching or color similarity thresholds to determine
which pixels to fill.
2D Transformations
Translation Rotation Scaling Reflection
Moves objects by adding Rotates objects around a Changes object size by Reflection creates the
constant values to x and point using trigonometric multiplying coordinates illusion of a mirrored
y coordinates. functions. by scaling factors. surface using techniques
like ray tracing. It's useful
for realistic materials like
glass, metal, or water.

2D transformations are fundamental operations in computer graphics that modify the position, orientation, and size of
objects in a two-dimensional space. Other important 2D transformations include reflection (flipping objects across an
axis) and shearing (slanting objects along one or both axes).
These transformations can be represented as matrix operations, allowing for efficient computation and combination of
multiple transformations. Homogeneous coordinates are often used to represent 2D points as 3D vectors, enabling all
transformations (including translation) to be expressed as matrix multiplications.
3D Transformations and Homogeneous
Coordinates
3D transformations extend the concepts of 2D transformations to three-dimensional space. These include:

Translation: Moving objects in 3D space


Rotation: Rotating around x, y, or z axes (or arbitrary axes)
Scaling: Changing object size in 3D
Reflection: Mirroring objects across planes
Shearing: Distorting objects in 3D space
Homogeneous coordinates play a crucial role in 3D graphics, representing 3D points as 4D vectors (x, y, z, w). This
allows all 3D transformations, including perspective projections, to be represented as 4x4 matrix multiplications. The use
of homogeneous coordinates simplifies the composition of multiple transformations and enables the representation of
points at infinity, which is essential for perspective projections in computer graphics.

You might also like