Computer Graphics

Chapter 2
Mathematical Foundations for Graphics

Post Graduate Program in Computer Science Engineering
Computer Graphics   •   Post Graduate

2. Mathematical Foundations for Graphics

Introduction and Context

Computer graphics is often presented through images, rendering systems, modeling software, and display hardware. Beneath each of these applications lies a mathematical language that describes position, direction, shape, transformation, visibility, interpolation, uncertainty, and sampling. A graphics program does not manipulate an abstract “object” directly; it operates on numerical representations of geometry, color, light, and space. The quality of a graphics system therefore depends greatly on whether its mathematical representations are appropriate, stable, and efficiently computed.

The mathematical foundations of graphics are interdisciplinary. Linear algebra describes coordinate systems and transformations; analytic geometry provides equations for lines, planes, curves, and intersections; calculus supports motion, shading, and optimization; numerical methods address approximation and error; probability and sampling theory explain antialiasing, Monte Carlo rendering, and uncertainty. These topics are not isolated techniques. They form a connected framework through which a three-dimensional scene becomes a two-dimensional image.

This chapter develops that framework with emphasis on interpretation and application. The objective is not merely to memorize formulas, but to understand why a particular representation or method is selected, what assumptions it makes, and how numerical decisions affect the final image.

Learning Objectives

After studying this chapter, the reader should be able to:

1. Explain the role of vectors, points, matrices, and coordinate systems in graphics.

2. Use homogeneous coordinates to represent affine transformations and perspective projection.

3. Apply dot products, cross products, determinants, and geometric equations to graphics problems.

4. Distinguish between local, world, view, and screen coordinate spaces.

5. Explain interpolation, barycentric coordinates, splines, and numerical approximation.

6. Analyze sampling, aliasing, probability distributions, and Monte Carlo estimation.

7. Identify sources of numerical instability and select suitable computational remedies.

8. Relate mathematical choices to rendering, animation, computer vision, simulation, and graphics hardware.

Geometry as a Computational Language

A point denotes a location, whereas a vector denotes a displacement or direction. Although both may be represented by an ordered triple such as (x,y,z), their meanings differ. Subtracting two points produces a vector, adding a vector to a point produces a point, and adding two points is generally not a meaningful geometric operation. Preserving this distinction improves both mathematical clarity and software design.

For vectors \(a=(a_x,a_y,a_z)\) and \(b=(b_x,b_y,b_z)\), the dot product is

\[a\cdot b=a_xb_x+a_yb_y+a_zb_z.\]

It measures directional similarity. If both vectors are nonzero, \(a\cdot b=|a||b|\cos\theta\), where \(\theta\) is the angle between them. The dot product supports projection, lighting calculations, back-face tests, and distance-to-plane computations. A normalized vector has unit length and is written \(\hat a=a/|a|\), provided \(|a|\neq0\).

The cross product in three-dimensional space is

\[a\times b=(a_yb_z-a_zb_y,\ a_zb_x-a_xb_z,\ a_xb_y-a_yb_x).\]

Its result is perpendicular to both input vectors, with magnitude equal to the area of the parallelogram they define. Given triangle vertices \(p_0,p_1,p_2\), a normal direction is obtained from \((p_1-p_0)\times(p_2-p_0)\). The order matters: reversing the order reverses the normal. This orientation is central to back-face culling, normal mapping, and determining the front side of a polygon.

A determinant measures signed area in two dimensions and signed volume in three dimensions. A zero determinant indicates linear dependence and, for a matrix, non-invertibility. Geometrically, a transformation with zero determinant collapses dimensional information; for example, a three-dimensional volume may be flattened onto a plane.

Coordinate Spaces and Homogeneous Representation

Graphics systems use several coordinate spaces because different tasks are easiest in different frames of reference. Object or model space describes geometry relative to its own origin. World space places objects in a common scene. View or camera space expresses the scene relative to the camera. Clip space is produced by projection, and normalized device coordinates result after perspective division. Finally, viewport or screen space maps normalized coordinates to pixels.

A homogeneous point is represented as \((x,y,z,w)\). Ordinary Euclidean coordinates are recovered by dividing by \(w\), when \(w\neq0\):

\[(x_e,y_e,z_e)=(x/w,y/w,z/w).\]

A point normally has \(w=1\), while a direction vector has \(w=0\). This distinction allows translation to be represented by matrix multiplication without treating a direction as a location.

An affine transformation can be written as a four-by-four matrix. A general transformation has the form

\[

M=\begin{bmatrix}A&t\\0&1\end{bmatrix},

\]

where \(A\) is a three-by-three linear transformation and \(t\) is a translation vector. Scaling, rotation, reflection, shear, and translation can therefore be combined into one representation. If column vectors are used, a transformed point is \(p'=Mp\). The convention must remain consistent throughout a system.

A translation by \(t_x,t_y,t_z\) is represented by

\[

T=\begin{bmatrix}1&0&0&t_x\\0&1&0&t_y\\0&0&1&t_z\\0&0&0&1\end{bmatrix}.

\]

Scaling uses diagonal entries \(s_x,s_y,s_z\). Rotation about the z-axis is

\[

R_z(\theta)=\begin{bmatrix}\cos\theta&-\sin\theta&0&0\\\sin\theta&\cos\theta&0&0\\0&0&1&0\\0&0&0&1\end{bmatrix}.

\]

Matrix multiplication is not commutative. In a column-vector convention, \(M=TR\) means that rotation is applied first and translation second. This is a frequent source of errors. A transformation hierarchy is usually evaluated by multiplying parent and local transforms in a carefully defined order.

The inverse of a rigid transformation is especially useful. If \(R\) is an orthonormal rotation and \(t\) is translation, then

\[

\begin{bmatrix}R&t\\0&1\end{bmatrix}^{-1}=

\begin{bmatrix}R^T&-R^Tt\\0&1\end{bmatrix}.

\]

This gives an efficient camera transformation from world space to view space. General matrix inversion is more expensive and may be unstable when the matrix is close to singular.

Projection and the Geometry of the Camera

Orthographic projection preserves parallelism and is commonly used in engineering views and interface diagrams. A perspective projection models the reduction in apparent size with distance. In a simple camera model, a point \((x,y,z)\) is projected onto a plane using relations proportional to \(x/z\) and \(y/z\), with the exact signs depending on the camera convention. The division by depth is the essential nonlinear operation.

A projection matrix maps view-space coordinates into clip space. After multiplication, perspective division by \(w\) produces normalized device coordinates. The depth coordinate is then mapped to the depth-buffer range. Near and far clipping planes define the visible depth interval. Because depth precision is not distributed uniformly in ordinary perspective projection, objects close to the near plane often receive greater precision than distant objects. Choosing a near plane that is unnecessarily close to the camera can therefore increase depth-fighting artifacts.

A ray is represented parametrically as

\[r(t)=o+td,\quad t\geq0,\]

where \(o\) is the origin and \(d\) is the direction. Ray tracing uses intersections between this equation and geometric primitives. For a sphere with center \(c\) and radius \(r\), intersection requires

\[|o+td-c|^2=r^2.\]

Expanding this expression gives a quadratic equation in \(t\). A negative discriminant means no real intersection; one zero means tangency; a positive value gives two intersection points. The smallest nonnegative valid root is normally the visible hit.

A plane can be expressed as

\[n\cdot p+d=0,\]

where \(n\) is a normal and \(d\) is a scalar. Substituting a ray produces

\[t=-\frac{n\cdot o+d}{n\cdot d},\]

provided the denominator is not zero. A small denominator indicates that the ray is parallel or nearly parallel to the plane, requiring a tolerance rather than an exact equality test.

Linear Algebra in Rendering and Modeling

A collection of vectors can be treated as a basis when the vectors are linearly independent and span the relevant space. A coordinate vector is not an absolute property of an object; it is a set of coefficients relative to a basis. This observation explains why changing coordinate systems changes numerical coordinates without changing the geometric object.

An eigenvector of a matrix is a direction that is changed only by scale, satisfying \(Av=\lambda v\). Eigenanalysis is not required for every rendering operation, but it is important in principal component analysis, shape analysis, physics, deformation, and understanding anisotropic behavior. Singular value decomposition decomposes a matrix into rotations and axis-aligned scaling, making it valuable for analyzing transformations, compression, and least-squares problems.

Normals require special care under nonuniform scaling. If a surface position is transformed by \(M\), a normal should generally be transformed by the inverse transpose of the linear part:

\[n'= (M^{-1})^Tn.\]

After transformation, the normal is usually renormalized. Applying the same position matrix directly to a normal can destroy perpendicularity when scaling differs along axes.

Interpolation and Parametric Representation

Interpolation constructs intermediate values from known samples. Linear interpolation between \(a\) and \(b\) is

\[L(a,b,t)=(1-t)a+tb,\quad 0\leq t\leq1.\]

It is used for positions, colors, texture coordinates, animation parameters, and camera motion. Values outside this interval produce extrapolation rather than interpolation.

For a triangle with vertices \(p_0,p_1,p_2\), barycentric coordinates \((\alpha,\beta,\gamma)\) satisfy

\[p=\alpha p_0+\beta p_1+\gamma p_2,\qquad \alpha+\beta+\gamma=1.\]

A point lies inside or on the triangle when all three coordinates are nonnegative. Barycentric coordinates allow attributes such as color, depth, and texture coordinates to be interpolated across rasterized triangles. In perspective projection, direct screen-space interpolation of texture coordinates can be incorrect. Perspective-correct interpolation uses values adjusted by reciprocal depth, commonly interpolating \(u/w\), \(v/w\), and \(1/w\), then dividing after interpolation.

Polynomial curves include Bézier curves, defined by control points and Bernstein basis functions. A quadratic Bézier curve is

\[B(t)=(1-t)^2P_0+2(1-t)tP_1+t^2P_2.\]

The curve begins at \(P_0\), ends at \(P_2\), and is generally influenced but not required to pass through \(P_1\). Cubic Bézier curves provide two interior control points and are widely used in font outlines, paths, and animation. Splines join polynomial segments while imposing continuity conditions. Position continuity is called C0 continuity; matching first derivatives gives C1 continuity, while stronger geometric or parametric conditions produce smoother curves.

Numerical Methods, Error, and Robustness

Graphics computations are performed with finite precision. Rounding error accumulates through transformations, interpolation, normalization, and repeated simulation steps. Two related concepts are important: accuracy concerns closeness to the true value, whereas stability concerns whether small input errors produce only small output errors.

Floating-point comparisons should rarely rely on exact equality. A geometric test such as \(n\cdot d=0\) is normally implemented with a tolerance related to the scale of the inputs. However, an arbitrary fixed epsilon can fail across scenes of very different sizes. Robust algorithms use scale-aware tolerances, consistent units, and well-conditioned representations.

Ill-conditioned problems amplify input errors. Nearly parallel ray-plane intersection, nearly degenerate triangles, and matrices with very small determinants are examples. Remedies include rescaling, using double precision, avoiding unnecessary subtraction of nearly equal numbers, and employing stable factorizations such as QR decomposition rather than explicitly forming an inverse.

Iterative methods are common in graphics. Newton's method updates an estimate according to

\[x_{k+1}=x_k-\frac{f(x_k)}{f'(x_k)}.\]

It can converge rapidly near a suitable solution but may diverge with a poor initial estimate or a small derivative. In physics and animation, time-step selection affects both accuracy and stability. An algorithm that is visually plausible at one frame rate may become unstable at another if its integration method is inappropriate.

Probability, Sampling, and the Formation of Images

Rendering often estimates an integral rather than evaluates it exactly. If a quantity is represented by a function \(f(x)\) over a domain, Monte Carlo estimation with samples drawn from probability density \(p(x)\) uses

\[\int f(x)dx\approx\frac{1}{N}\sum_{i=1}^{N}\frac{f(X_i)}{p(X_i)}.\]

The estimator is unbiased under appropriate conditions, but its variance determines noise. Increasing the number of independent samples generally reduces standard error at a rate proportional to \(1/\sqrt{N}\), which means that substantial additional computation may be required for modest visual improvement.

Importance sampling chooses more samples where the integrand contributes strongly. In light transport, sampling a light source or a distribution related to the material's reflectance can reduce variance. Stratified sampling divides a domain into regions and samples each region, reducing clustering. Low-discrepancy sequences distribute samples more evenly than purely random sequences, although their theoretical and practical advantages depend on the integration problem.

Sampling theory explains aliasing. A continuous signal sampled below a sufficient rate can produce false lower-frequency patterns. In images, undersampling creates jagged edges, moiré patterns, flicker, and temporal instability. Antialiasing approaches include supersampling, analytical coverage computation, filtering, multisample techniques, and temporal accumulation. A reconstruction filter combines samples to estimate pixel values; its width and shape affect sharpness, ringing, and noise.

The Nyquist perspective is useful but incomplete for graphics because rendered signals are not always band-limited and visibility boundaries contain high frequencies. Practical systems therefore combine geometric filtering, pixel footprints, adaptive sampling, and post-processing. Temporal sampling introduces another dimension: a moving object may be misrepresented if exposure and motion are sampled inadequately, producing strobing or incorrect motion blur.

Practical and Professional Applications

These mathematical tools support a broad range of graphics systems. In a game engine, hierarchical matrices place a character's skeleton, transform vertices into camera space, and project them to the screen. In a CAD system, exact geometric predicates and coordinate transformations support measurement and manufacturing constraints. In visual effects, ray-primitive intersections, probability distributions, and numerical integration produce realistic lighting. In computer vision, camera matrices, homogeneous coordinates, and least-squares estimation recover scene structure from images.

Graphics engineers must also make architectural decisions. Matrix layout, multiplication convention, precision, coordinate handedness, depth range, and unit scale should be documented at the system level. Inconsistent conventions can cause errors that appear as artistic defects but are actually interface failures between tools, shaders, and asset pipelines.

Modern GPUs implement large portions of the transformation and rasterization pipeline in specialized hardware. Shader programs expose vector and matrix operations, while graphics APIs provide projections, buffers, textures, and synchronization mechanisms. Machine-learning-based denoisers, neural super-resolution, and learned sampling strategies increasingly complement classical numerical methods. Nevertheless, learned components still depend on sound coordinate systems, sampling assumptions, and error analysis.

Illustrative Case Study: Stabilizing a Real-Time Architectural Viewer

Background

A fictional architectural-visualization team develops a real-time viewer for a large building model. Users report flickering surfaces, incorrect texture alignment, and occasional shadows that appear detached from geometry.

Situation and Analysis

The model combines assets from several design tools. Some assets use meters and others millimeters; one import path uses a left-handed coordinate system while the engine assumes a right-handed system. The viewer also places the camera's near clipping plane extremely close to the eye. Investigation shows that normals are transformed with the model matrix even when models use nonuniform scaling. Finally, texture coordinates are linearly interpolated in screen space without perspective correction.

Approach and Solution

The team defines a single world-unit convention and converts all imported geometry during ingestion. A documented transformation pipeline is established: object space to world space, world space to view space, view space to clip space, and clip space to viewport space. Handedness is converted explicitly rather than implicitly. Rigid camera transforms use the transpose of the rotation for inversion. Normal transformations use the inverse transpose of the model's linear component.

The near clipping plane is moved farther from the camera while the far plane is reconsidered. Depth precision is tested across representative scenes. Perspective-correct interpolation is enabled for texture coordinates, and a small scale-aware offset is used for secondary rays to reduce self-intersection artifacts. Degenerate triangles and zero-length normals are rejected during asset validation.

Outcome

The visual defects are substantially reduced, and the same assets behave consistently across scenes. The main improvement does not come from a single sophisticated algorithm; it comes from consistent mathematical conventions, validation, and attention to numerical conditioning.

Learning Points

The case demonstrates that mathematical foundations are system-design concerns, not merely theoretical prerequisites. Coordinate conventions, matrix order, normal transformation, depth precision, interpolation, and tolerances interact. A local fix can conceal a pipeline-level inconsistency, whereas an explicit mathematical contract improves reliability and maintainability.

Limitations, Risks, and Common Mistakes

Common mistakes include confusing points and vectors, multiplying matrices in the wrong order, mixing row-vector and column-vector conventions, normalizing a zero vector, and assuming that a determinant close to zero can safely be treated as nonzero. Other errors include using degrees where a trigonometric function expects radians, forgetting perspective correction, and selecting a clipping range that wastes depth precision.

Random sampling can produce visible noise, while poorly chosen importance distributions can increase variance rather than reduce it. Supersampling improves quality at additional computational cost and does not automatically solve temporal aliasing. Iterative numerical methods may fail without convergence tests, iteration limits, and appropriate initial conditions.

Professional systems should validate inputs, expose units and conventions, record precision assumptions, and test pathological cases: very large and very small coordinates, nearly parallel lines, degenerate triangles, extreme camera angles, and objects close to clipping boundaries.

Ethical and Professional Considerations

Mathematical reliability has ethical consequences when graphics supports medical visualization, scientific communication, navigation, training, or public decision-making. A visually persuasive rendering may still be physically or geometrically misleading. Engineers should distinguish measured data from simulated content, document approximations, preserve reproducibility, and avoid presenting uncertain results with unjustified precision. In safety-critical visualization, validation and traceability are more important than merely achieving visual realism.

Current Developments and Best Practices

Current graphics research combines physically based models with stochastic estimation, differentiable rendering, neural representations, adaptive sampling, and hardware-accelerated ray tracing. Differentiable graphics uses derivatives of rendering computations for inverse problems such as estimating shape, material, or lighting from images. Neural radiance fields and related representations demonstrate how learned functions can encode view-dependent appearance, but their quality remains dependent on sampling, camera calibration, and generalization.

A robust practice is to treat mathematical conventions as part of the software interface. Use typed or semantically distinct point and vector representations where possible; centralize transformation construction; test inverse transformations; normalize only when meaningful; use stable algorithms; select tolerances relative to scale; and measure sampling error rather than judging only by isolated visual examples. These practices make advanced methods more dependable.

Chapter Summary

Mathematical foundations provide the language through which graphics systems represent and manipulate scenes. Vectors describe directions and displacements, matrices encode linear and affine transformations, and homogeneous coordinates unify translation, projection, and coordinate-space conversion. Dot and cross products support projection, orientation, normals, lighting, and intersection tests. Parametric geometry and barycentric coordinates provide effective representations for curves, triangles, and interpolated attributes.

Numerical methods are essential because graphics computations use finite precision and often solve approximate problems. Stability, conditioning, tolerances, and suitable iterative methods determine whether an implementation remains reliable under difficult inputs. Probability and sampling theory explain Monte Carlo rendering, importance sampling, antialiasing, variance, and temporal artifacts. Together, these concepts support rendering, animation, modeling, computer vision, simulation, and modern GPU-based systems.

Key Terms

Vector: A directed quantity representing displacement or direction.

Point: A location in a coordinate space.

Dot product: A scalar product measuring directional alignment.

Cross product: A three-dimensional product producing a perpendicular vector.

Normal: A vector perpendicular to a surface or geometric element.

Homogeneous coordinates: An augmented coordinate representation enabling projective transformations.

Affine transformation: A transformation preserving lines and parallelism, including translation.

Basis: A linearly independent set of vectors spanning a space.

Determinant: A scalar indicating signed scale, orientation, and invertibility of a square matrix.

Coordinate space: A reference frame in which geometric quantities are expressed.

Perspective division: Division by homogeneous depth or w coordinate after projection.

Barycentric coordinates: Weights expressing a point relative to a triangle's vertices.

Interpolation: Estimation of intermediate values from known values.

Conditioning: Sensitivity of a problem's result to changes in its input.

Numerical stability: The ability of an algorithm to limit the amplification of computational errors.

Monte Carlo estimation: Approximation of an integral using random or probabilistic samples.

Importance sampling: Sampling according to a distribution that emphasizes influential regions.

Aliasing: Misrepresentation caused by inadequate sampling of a signal.

Reconstruction filter: A filter used to estimate a continuous or pixel value from samples.

Inverse transpose: The matrix operation commonly used to transform normals under nonuniform scaling.

Review Questions

Short Answer Questions

1. Distinguish between a point and a vector in geometric computation.

2. What information does the dot product provide about two vectors?

3. Why are homogeneous coordinates useful in graphics?

4. Define barycentric coordinates for a triangle.

5. What is aliasing, and why does it occur?

Long Answer Questions

1. Explain the transformation from object space to screen space and discuss the role of each coordinate space.

2. Derive the ray-plane intersection equation and explain the parallel-ray case.

3. Discuss why normals require inverse-transpose transformation under nonuniform scaling.

4. Explain Monte Carlo rendering, variance, importance sampling, and the effect of sample count.

5. Compare orthographic and perspective projection, including their applications and limitations.

Analytical / Application Questions

1. A model is scaled by factors 2, 1, and 0.5 along its axes. Explain why transforming a surface normal with the model matrix may be incorrect and specify a suitable method.

2. A renderer exhibits flickering on distant coplanar surfaces. Analyze the likely depth-buffer causes and propose two mathematically justified remedies.

3. A texture appears distorted on a receding triangle even though its vertex texture coordinates are correct. Explain the interpolation error and identify the appropriate correction.

22. Multiple Choice Questions with Answers

Question 1

A graphics system transforms a point using a matrix with homogeneous coordinate w = 2. What Euclidean point is represented by (6, 4, 10, 2)?

A. (6, 4, 10)

B. (3, 2, 5)

C. (12, 8, 20)

D. (4, 2, 8)

Correct Answer: B. (3, 2, 5)

Question 2

Which operation is most directly used to determine whether two nonzero vectors are perpendicular?

A. Their determinant

B. Their cross-product magnitude

C. Their dot product

D. Their homogeneous division

Correct Answer: C. Their dot product

Question 3

For a column-vector convention, the matrix product TR applies which operation first?

A. Translation

B. Rotation or other operation represented by R

C. Perspective division

D. Viewport mapping

Correct Answer: B. Rotation or other operation represented by R

Question 4

Why is the inverse transpose used to transform normals under nonuniform scaling?

A. It preserves texture coordinates

B. It preserves perpendicularity to transformed surfaces

C. It removes perspective division

D. It converts points into vectors

Correct Answer: B. It preserves perpendicularity to transformed surfaces

Question 5

A ray-plane intersection calculation has a denominator n·d very close to zero. What does this most likely indicate?

A. The ray is nearly parallel to the plane

B. The ray starts at the plane's origin

C. The plane has zero area

D. The ray must intersect twice

Correct Answer: A. The ray is nearly parallel to the plane

Question 6

Which barycentric-coordinate condition indicates that a point lies inside or on a triangle?

A. All coordinates are negative

B. Their sum is zero

C. All coordinates are nonnegative and sum to one

D. Exactly one coordinate equals one

Correct Answer: C. All coordinates are nonnegative and sum to one

Question 7

In Monte Carlo integration, sampling with density p(x) generally requires each sample contribution to be weighted by:

A. p(x)

B. 1/p(x)

C. p(x)^2

D. The determinant of the camera matrix

Correct Answer: B. 1/p(x)

Question 8

If the number of independent samples is increased by a factor of four, the standard Monte Carlo error approximately becomes:

A. Twice as large

B. Unchanged

C. Half as large

D. One-fourth as large

Correct Answer: C. Half as large

Question 9

Which situation is a typical example of aliasing?

A. A normalized vector having unit length

B. A distant repeating texture producing moiré patterns

C. A rigid transform preserving distances

D. A plane equation having a nonzero normal

Correct Answer: B. A distant repeating texture producing moiré patterns

Question 10

Why can moving the near clipping plane farther from the camera improve depth-buffer behavior?

A. It removes all perspective effects

B. It increases color precision

C. It can improve the distribution of available depth precision

D. It changes vectors into points

Correct Answer: C. It can improve the distribution of available depth precision

Computer Graphics
Chapter 2 of 15