Computer Graphics
Computer Graphics
Contents
1 Unit 1: Introduction to Computer Graphics 3
1.1 Video-Display Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Raster-Scan and Random-Scan Systems . . . . . . . . . . . . . . . . . . 3
1.3 Graphics Monitors and Input Devices . . . . . . . . . . . . . . . . . . . . 4
1.4 Points and Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Line Drawing Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5.1 DDA (Digital Differential Analyzer) Algorithm . . . . . . . . . . 4
1.5.2 Bresenham’s Line Algorithm . . . . . . . . . . . . . . . . . . . . . 5
1.6 Circle and Ellipse Drawing Algorithms . . . . . . . . . . . . . . . . . . . 6
1.6.1 Mid-Point Circle Algorithm . . . . . . . . . . . . . . . . . . . . . 6
1.6.2 Mid-Point Ellipse Algorithm . . . . . . . . . . . . . . . . . . . . . 7
1.7 Area Filling Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.7.1 Scan Line Polygon Fill . . . . . . . . . . . . . . . . . . . . . . . . 8
1.7.2 Boundary Fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.7.3 Flood Fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1
2.6 Exercises....................................................................................................................17
4 Practice Questions 24
2
1 Unit 1: Introduction to Computer Graphics
1.1 Video-Display Devices
Video-display devices render graphical content on screens, essential for computer graphics
visualization.
Types:
• LED Displays: Use light-emitting diodes for vibrant colors and better contrast.
Use Cases:
Summary: Video-display devices (CRT, LCD, LED) vary in technology and appli-
cation. LCD and LED dominate due to efficiency and quality.
Mathematical Basis:
• Raster-Scan: Represents image as a matrix I(x, y), where each element is a pixel
intensity.
• Random-Scan: Uses parametric equations, e.g., line from (x0, y0) to (x1, y1).
Use Cases:
3
Table 1: Comparison of Raster-Scan and Random-Scan Systems
Feature Raster-Scan Random-Scan
Display Method Pixel grid Vector paths
Image Quality Smooth for filled areas Sharp for lines
Applications General-purpose displays CAD, vector graphics
Types:
Use Cases:
Summary: Monitors and input devices bridge user interaction and graphical output,
critical for graphics applications.
Mathematical Representation:
Mathematical Formula:
∆x = x1 − x0, ∆y = y1 − y0
4
Steps = max(|∆x|, |∆y|)
∆x ∆y
xinc = , yinc =
Steps Steps
Algorithm:
11
Example: Draw line from (2, 3) to (6, 5). Steps = 4, xinc = 1, yinc = 0.5. Plot (2, 3),
(3, 3.5), (4, 4), (5, 4.5), (6, 5).
Summary: DDA uses floating-point arithmetic for smooth line drawing, suitable for
raster displays.
Mathematical Formula:
∆x = |x1 − x0|, ∆y = |y1 − y0|
Error = ∆x − ∆y
If 2 · Error > −∆y, update x; else, update y
Algorithm:
12
Example: Line from (1, 1) to (4, 3). ∆x = 3, ∆y = 2. Plot (1, 1), (2, 1), (3, 2), (4, 3).
Mathematical Formula:
x2 + y2 = r2
Decision parameter: d = 1 − r
If d < 0, update d+ = 2x + 3; else, d+ = 2(x − y) + 5, y − −
Algorithm:
1. Initialize x = 0, y = r, d = 1 − r.
4. Repeat until x ≤ y.
1 void MidPointCircle(int xc, int yc, int r) {
2 int x = 0, y = r;
3 int d = 1 - r;
4
while (x <= y) {
plot(xc + x, yc + y); plot(xc - x, yc + y);
6
5
7
6 plot(xc + x, yc - y); plot(xc - x, yc - y);
7 plot(xc + y, yc + x); plot(xc - y, yc + x);
8 plot(xc + y, yc - x); plot(xc - y, yc - x);
9 if (d < 0) d += 2 * x + 3;
10 else { d += 2 * (x - y) + 5; y--; }
11 x++;
12 }
13 }
Diagram:
(xc, yc + r)
(xc, yc − r)
Example: Circle at (0, 0) with radius 3. Plot symmetric points like (0, 3), (3, 0), etc.
Summary: Mid-point circle algorithm leverages symmetry for efficient circle draw-
ing.
Mathematical Formula:
x2 y2
+ =1
r2x r2y
d1 = r2 − r2ry + 0.25r2
y x x
Algorithm:
1. Initialize x = 0, y = ry, d1 = r2 − r2ry + 0.25r2.
y x x
8
1 void MidPointEllipse(int xc, int yc, int rx, int ry) {
2
int x = 0, y = ry;
3
int d1 = ry*ry - rx*rx*ry + 0.25* rx*rx;
int dx = 2*ry*ry*x, dy = 2*rx*rx*y;
4
while (dx < dy) {
5
plot(xc + x, yc + y); plot(xc - x, yc + y);
6 plot(xc + x, yc - y); plot(xc - x, yc - y);
7 if (d1 < 0) { dx += 2*ry*ry; d1 += dx + ry*ry; }
8 else { dx += 2*ry*ry; dy -= 2*rx*rx; d1 += dx - dy + ry*ry;
9
y--; }
x++;
}
10
// Region 2 code omitted for brevity
11
}
12
13
Example: Ellipse at (0, 0) with rx = 4, ry = 3. Plot symmetric points like (0, 3), (4, 0).
Summary: Mid-point ellipse algorithm adapts circle drawing for ellipses, handling
dual radii.
Algorithm:
Example: Fill a triangle with vertices (0, 0), (4, 4), (8, 0). Scan lines intersect edges,
filling between points.
Summary: Scan line fill is efficient for complex polygons, processing scan lines in-
dependently.
Algorithm:
9
2. Plot pixel with fill color.
10
3. Recursively call for neighboring pixels.
1 void BoundaryFill(int x, int y, int fillColor , int boundaryColor) {
2
if ( getPixel(x, y) != boundaryColor && getPixel(x, y) !=
fillColor) {
plot(x, y, fillColor);
3
BoundaryFill(x + 1, y, fillColor ,
4
boundaryColor); BoundaryFill(x - 1, y, fillColor
5 , boundaryColor); BoundaryFill(x, y + 1,
6 fillColor , boundaryColor); BoundaryFill(x, y -
7 1, fillColor , boundaryColor);
8
}
}
9
Example: Fill a square with boundary color black and fill color red from seed point (2, 2).
Summary: Boundary fill is simple but slow for large areas due to recursion.
Algorithm:
Summary: Flood fill is effective for uniform color regions but risks stack overflow.
1.8 Exercises
1. Which factor determines the number of steps in the DDA algorithm?
11
A. Minimum of ∆x, ∆y
12
B. Maximum of |∆x|, |∆y|
C. Sum of ∆x, ∆y
D. Product of ∆x, ∆y
A. ∆x + ∆y
B. ∆x − ∆y
C. 2∆x − ∆y
D. ∆y − ∆x
3. For a circle with radius 5, the initial decision parameter in the mid-point algorithm
is:
A. 1 − r
B. r − 1
C. r2
D. 0
4. Which algorithm is most suitable for filling a polygon with many vertices?
A. Boundary Fill
B. Flood Fill
C. Scan Line
D. Mid-Point
A. 1
B. 2
13
C. 4
D. 8
Answer: B. Explanation: The algorithm divides the ellipse into two regions
based on slope.
D. Both B and C
7. For a line from (0, 0) to (4, 6), how many pixels are plotted by Bresenham’s
algorithm (including endpoints)?
A. 5
B. 6
C. 7
D. 8
A. Raster-Scan
B. Random-Scan
C. Both
D. Neither
A. Integer arithmetic
B. Floating-point arithmetic
C. Both
14
D. None
B. Stack overflow
C. Complex calculations
D. Pixel overlap
Answer: B. Explanation: Recursive calls can exhaust stack space in large regions.
2.1.1 Translation
Moves an object by adding offsets.
Mathematical Formula:
(x′, y′) = (x + tx, y + ty)
2.1.2 Scaling
Resizes an object relative to a fixed point.
Mathematical Formula:
(x′, y′) = (x · sx, y · sy)
Summary: Scaling changes size; uniform scaling (sx = sy) preserves shape.
2.1.3 Rotation
Rotates an object around the origin by angle θ.
15
Mathematical Formula:
Diagram:
(x′, y′(x,
)
y)
θ x
2.1.4 Reflection
Mirrors an object over an axis.
Mathematical Formula:
X-axis: (x′, y′) = (x, −y)
Y-axis: (x′, y′) = (−x, y)
2.1.5 Shear
Distorts an object along an axis.
Mathematical Formula:
16
Summary: Shear creates slanted distortions for visual effects.
Mathematical Formulas:
1 0 tx
Translation: 0 1 ty
0 0 1
sx 0 0
Scaling: 0 sy 0
0 0 1
cos θ − sin θ 0
Rotation: sin θ cos θ 0
0 0 1
Mathematical Formula:
M = M1 · M2 · . . . · Mn
17
2.4 Viewing Concepts
2.4.1 Viewing Pipeline
Maps objects from world to screen coordinates through transformations.
Algorithm:
4. Map to viewport.
Mathematical Formula:
(xw − xwmin)(xvmax − xvmin)
x = + xvmin
v xwmax − xwmin
(yw − ywmin)(yvmax − yvmin)
y = + yvmin
ywmax − ywmin
v
Example: Map (5, 5) from window [0, 10] × [0, 10] to viewport [0, 100] × [0, 100] yields
(50, 50).
Algorithm:
18
1 void CohenSutherland(float x0 , float y0 , float x1 , float y1 , float
xmin , float ymin , float xmax , float ymax) {
2
int code0 = computeCode(x0 , y0 , xmin , ymin , xmax , ymax);
int code1 = computeCode(x1 , y1 , xmin , ymin , xmax , ymax);
3
while (true) {
if (!( code0 | code1 )) { accept(); break; }
if (code0 & code1 ) { reject(); break; }
// Clip and update endpoints
}
}
Diagram
:
0001
0100
Mathematical Formula:
Algorithm
:
19
2.5.3 Sutherland-Hodgman Polygon Clipping
Clips polygons against convex clip windows.
Algorithm:
2.6 Exercises
1. The homogeneous coordinate for point (2, 3) is:
A. (2, 3, 0)
B. (2, 3, 1)
C. (1, 2, 3)
D. (3, 2, 1)
A. (0, 1)
B. (0, -1)
C. (-1, 0)
D. (1, 0)
20
Answer: A. Explanation: Matrix multiplication is non-commutative (AB ̸=
BA).
4. For window [0, 10] × [0, 10] and viewport [0, 100] × [0, 100], point (5, 5) maps to:
A. (50, 50)
B. (5, 5)
C. (100, 100)
D. (25, 25)
(5−0)(100−0)
Answer: A. Explanation: Linear mapping yields xv = 10−
= 50.
0
5. Cohen-Sutherland rejects a line if:
Answer: B. Explanation: Non-zero AND indicates both points are outside same
boundary.
A. Region codes
B. Parametric equations
C. Vertex lists
D. Edge tables
A. Concave windows
B. Convex windows
C. Circular windows
D. Any shape
21
8. A shear transformation can:
A. Rotate objects
B. Distort shapes
C. Scale uniformly
D. Reflect objects
C. Translation, reflection
22
Example: A cube defined by 8 vertices and 12 triangular faces.
n ( )
P (t) = ∑ n ti(1 − t)n−i
Bi,n(t)Pi, Bi,n(t) =
i
i=0
Summary: Splines provide smooth, flexible representations for curves and surfaces.
Mathematical Formulas:
Iambient = kaIa
Idiffuse = kdId(N · L)
Ispecular = ksIs(R ·
V)n
Diagram
:
Surface L
23
Example: Lighting a 3D model with ambient for base, diffuse for shading, specular for
highlights.
24
Summary: Illumination models combine ambient, diffuse, and specular for realistic
lighting.
Algorithm:
4. Map to viewport.
Diagram:
Perspective
Orthographic
25
Summary: Perspective adds realism; orthographic suits technical drawings.
Algorithm:
3.6 Exercises
1. The equation for a sphere is:
A. x2 + y2 = r2
B. x2 + y2 + z2 = r2
C. x + y + z = r
D. x2 + y2 = z
A. Control points
B. Edge tables
C. Region codes
D. Parametric lines
Answer: A. Explanation: Bezier curves use control points for smooth interpola-
tion.
26
C. Ambient intensity
D. Diffuse coefficient
A. Vertex colors
B. Surface normals
C. Pixel intensities
D. Edge coordinates
A. z-division
B. Uniform scaling
C. Orthogonal vectors
D. Shear components
A. World coordinates
B. View frustum
C. Screen coordinates
D. Viewport
A. Local control
B. Global control
C. Linear interpolation
D. Fixed endpoints
27
Answer: A. Explanation: B-Splines allow local modifications.
C. Translation, reflection
A. N · V
B. N · L
C. R · V
D. L · R
Answer: B. Explanation: Diffuse uses normal and light direction dot product.
A. Depth
B. Parallel lines
C. Angles
D. Curvature
4 Practice Questions
The following 100 multiple-choice questions are designed to test your understanding of
computer graphics concepts. Attempt these to reinforce your knowledge.
A. Higher resolution
B. Energy efficiency
28
D. Larger size
A. Random-Scan
B. Raster-Scan
C. Vector-Scan
D. None
A. Keyboard
B. Mouse
C. Graphic tablet
D. Joystick
A. 0.5
B. 1
C. 2
D. 4
A. Line length
D. Pixel density
A. Floating-point arithmetic
B. Integer arithmetic
C. Complex numbers
D. Matrix operations
29
7. The mid-point circle algorithm uses how many symmetric points?
A. 4
B. 6
C. 8
D. 12
A. rx + ry
B. r2 + r2
x y
C. r2 − r2ry
y x
D. r − r2
2
x y
A. Edge table
B. Vertex colors
C. Boundary colors
D. Seed points
A. Large areas
C. Complex polygons
D. Non-convex shapes
A. Boundary color
B. Specified color
C. Edge pixels
D. Vertex colors
30
A. DDA
B. Bresenham
C. Mid-Point Circle
D. Scan Line
A. Parametric equations
B. Decision parameters
C. Edge intersections
D. Vertex normals
A. CRT
B. LCD
C. LED
D. Plasma
15. The DDA algorithm is less efficient than Bresenham’s due to:
A. Integer calculations
B. Floating-point calculations
C. Memory usage
D. Recursion
A. 1
B. 2
C. 3
D. 4
A. Uses recursion
31
B. Processes scan lines independently
D. Uses floating-point
A. Stack overflow
B. Memory leaks
C. Pixel overlap
D. Edge artifacts
A. Filled shapes
B. Vector graphics
C. Raster images
D. 3D rendering
A. DDA
B. Bresenham
C. Both
D. Neither
A. Size
B. Orientation
C. Position
D. Shape
A. Non-uniform scaling
B. Uniform scaling
32
C. Shear scaling
D. Reflective scaling
A. (0, 1)
B. (-1, 0)
C. (0, -1)
D. (1, 0)
A. X-coordinate based on y
B. Y-coordinate based on x
C. Both coordinates
D. Neither coordinate
B. Scaling only
C. Rotation only
D. Clipping
33
27. The composite transform M1 · M2 is equivalent to:
A. M2 · M1
B. Applying M2 then M1
C. Applying M1 then M2
D. Inverse of M1
A. Projection
B. Modeling
C. Clipping
D. Viewport mapping
A. Rotation
C. Reflection
D. Shear
A. 2
B. 4
C. 6
D. 8
A. Complex polygons
B. Short lines
C. Parametric lines
D. Curved lines
34
A. Clipped lines
B. Clipped polygons
C. Clipped points
D. Clipped curves
A. Commutative
B. Non-commutative
C. Singular
D. Orthogonal
35. The region code for a point left of the window is:
A. 0001
B. 0010
C. 0100
D. 1000
A. Object position
B. Camera position
35
C. Screen position
D. Viewport size
A. Modeling
B. Projection
C. Viewport mapping
D. Rotation
A. 2
B. 3
C. 4
D. 5
A. Same matrix
B. Negative offsets
C. Zero offsets
D. Identity matrix
A. Angles
B. Distances
C. Relative positions
D. Shapes
A. Smooth curves
B. Hardware rendering
C. Parametric surfaces
36
D. Fractal shapes
A. Linear equations
B. Quadratic equations
C. Cubic equations
D. Parametric equations
A. Global control
B. Local control
C. Vertex normals
D. Edge tables
A. Direction-dependent
B. Uniform
C. Specular
D. Diffuse
A. Viewer direction
B. Light direction
C. Reflection vector
D. Surface color
C. Equal to Gouraud
37
47. Perspective projection simulates:
A. Parallel lines
B. Depth
C. Uniform scaling
D. Orthogonal views
A. Games
B. CAD
C. Animation
D. Virtual reality
A. View frustum
B. Screen boundaries
C. World coordinates
D. Viewport edges
A. Fixed endpoints
B. Local modifications
C. Global control
D. Linear paths
A. Modeling
B. Projection
C. Viewport mapping
D. Clipping
38
A. N · L = 1
B. R · V = 1
C. N · V = 1
D. L · R = 1
A. Interpolated normals
B. Uniform color
C. Vertex colors
D. Pixel intensities
A. Polygon surface
B. Quadric surface
C. Spline surface
D. Bezier curve
A. 2
B. 3
C. 4
D. 5
A. 4
B. 5
C. 6
D. 8
A. Vertex coordinates
39
B. Pixel intensities
C. Edge lists
D. Normal vectors
A. Line drawings
B. Filled shapes
C. Vector graphics
D. CAD designs
A. Integer steps
B. Floating-point increments
C. Decision parameters
D. Region codes
A. |m| < 1
B. |m| > 1
C. Any slope
D. m = 0
A. Symmetry
B. Recursion
C. Edge tables
D. Parametric equations
A. Y-coordinate
B. X-coordinate
40
C. Z-coordinate
D. Color value
A. 2
B. 4
C. 6
D. 8
D. Is non-recursive
A. 2x2
B. 2x3
C. 3x3
D. 3x2
A. Position
B. Orientation
C. Size
D. Color
A. Singular
B. Orthogonal
C. Diagonal
41
D. Skew-symmetric
A. Vertex positions
B. Window boundaries
C. Parametric equations
D. Edge intersections
A. Region codes
B. Intersection parameters
C. Vertex lists
D. Edge tables
A. Curves
B. Triangles or quads
C. Splines
D. Quadrics
A. Surface normal
B. Light direction
C. No direction
D. Viewer position
42
73. Gouraud shading interpolates:
A. Normals
B. Colors
C. Textures
D. Coordinates
A. 3x3
B. 4x4
C. 3x4
D. 4x3
A. X-coordinate
B. Y-coordinate
C. Z-coordinate
D. W-coordinate
A. World space
B. View space
C. Screen space
D. Model space
C. Edge lists
D. Vertex normals
43
A. ka
B. kd
C. ks
D. n
A. Screen to world
B. World to screen
C. Viewport to model
D. Model to viewport
A. Cube
B. Sphere
C. Triangle mesh
D. Bezier curve
A. Global continuity
B. Local continuity
C. No continuity
D. Endpoint interpolation
A. 4 planes
B. 6 planes
C. 8 planes
D. 10 planes
44
B. Sine of angle between normal and viewer
A. Interpolating colors
B. Interpolating normals
D. Reducing calculations
A. Origin
B. Vanishing point
C. Viewport center
D. Infinity
A. Realistic rendering
B. Technical drawings
C. Animation
D. Games
45