The applications of linear algebra in computer graphics include representing objects, changing their positions, rotating shapes, adjusting their sizes, and converting three-dimensional scenes into two-dimensional images. Computer graphics systems use vectors, matrices, and mathematical transformations to perform these operations.
When you play a video game, watch an animated movie, or design a three-dimensional model, mathematical calculations determine how objects appear and move on the screen. Linear algebra allows computers to perform these calculations in an organized and efficient way.
Coordinate systems, transformation matrices, affine geometry, and projection matrices form the mathematical foundation of computer graphics. These concepts have further applications in cryptography, computed tomography, graph theory, electrical circuits, and computer programming.
This article explains how linear algebra works in computer graphics through mathematical formulas, practical applications, and step-by-step solved examples.
Description
Linear algebra is a branch of mathematics that studies vectors, matrices, vector spaces, linear transformations, and systems of linear equations.
Computer graphics is a field of computer science concerned with creating, modifying, and displaying digital images and animations.
Linear algebra connects mathematics with computer graphics by providing methods for representing and transforming graphical objects.
For example, a triangle can be represented using three points:
A = (1, 2)
B = (4, 2)
C = (3, 5)
A computer stores these coordinates and applies mathematical operations whenever the triangle changes its position, size, or orientation.
There are eight major applications of linear algebra in computer graphics.
| Application | Mathematical concept |
|---|---|
| Object movement | Translation vectors |
| Object resizing | Scaling matrices |
| Object rotation | Rotation matrices |
| Camera positioning | View matrices |
| Three-dimensional rendering | Projection matrices |
| Lighting and shading | Dot products and normal vectors |
| Character animation | Matrix transformations and quaternions |
| Image processing | Matrix operations and decompositions |
Graphics software such as Blender, Autodesk Maya, Unity, and Unreal Engine uses mathematical operations to process graphical objects.
Graphics application programming interfaces (APIs), including OpenGL, Direct3D, Vulkan, WebGL, and Metal, provide tools for performing graphics operations on computer hardware.
From 2D to 3D
Two-dimensional (2D) graphics represent objects using horizontal and vertical coordinates. Three-dimensional (3D) graphics introduce a third coordinate to represent depth.
A point in two dimensions has the form:
P = (x, y)
A point in three dimensions has the form:
P = (x, y, z)
The third dimension allows computers to represent the height, width, and depth of objects.
| Property | 2D graphics | 3D graphics |
|---|---|---|
| Number of spatial axes | 2 | 3 |
| Coordinates | (x, y) | (x, y, z) |
| Spatial dimensions | Width and height | Width, height, and depth |
| Linear transformation matrix | 2 × 2 | 3 × 3 |
| Homogeneous transformation matrix | 3 × 3 | 4 × 4 |
| Examples | Logos, charts, icons | Games, animations, virtual environments |
Three-dimensional graphics require coordinate transformations to position objects within a scene and project those objects onto a flat computer screen.
The Cartesian Plane
The Cartesian plane is a two-dimensional coordinate system consisting of two perpendicular axes called the x-axis and y-axis.
Perpendicular axes are described mathematically as orthogonal axes.
The point where both axes intersect is called the origin.
O = (0, 0)
Consider the point:
P = (3, 5)
The point lies three units along the positive x-axis and five units along the positive y-axis relative to the origin.
A three-dimensional Cartesian coordinate system introduces the z-axis, which is perpendicular to both the x-axis and y-axis.
For example:
P = (3, 5, 2)
The point has three coordinates representing its position along the three spatial axes.
The standard basis vectors in three dimensions are:
e₁ = (1, 0, 0)
e₂ = (0, 1, 0)
e₃ = (0, 0, 1)
Every vector in three-dimensional Cartesian space can be expressed as a linear combination of these basis vectors.
For example:
v = (3, 5, 2)
v = 3e₁ + 5e₂ + 2e₃
Graphics programmers use basis vectors to describe object orientation, camera direction, movement, and coordinate frames.
Handedness
Handedness describes the orientation of the three coordinate axes in a three-dimensional space.
There are two common coordinate system conventions:
- Right-handed coordinate system.
- Left-handed coordinate system.
In a right-handed coordinate system, the positive directions of the x-axis, y-axis, and z-axis follow the right-hand rule.
Mathematically:
eₓ × eᵧ = e_z
A left-handed coordinate system reverses the orientation relative to a right-handed system.
Handedness affects rotation direction, camera orientation, cross products, and the interpretation of surface normals.
OpenGL commonly uses right-handed viewing coordinates. Direct3D supports both right-handed and left-handed conventions through suitable transformation matrices. Metal uses its own clip-space conventions.
Graphics developers must maintain consistent coordinate conventions when transferring models between graphics engines and rendering systems.
A mismatch between coordinate systems can cause objects to appear mirrored, incorrectly rotated, or positioned in the wrong direction.
Introduction to Transformations
A geometric transformation is a mathematical operation that changes the coordinates of a point or an object.
Computer graphics uses five common geometric transformations.
| Transformation | Purpose |
|---|---|
| Identity | Preserves the original coordinates |
| Translation | Changes object position |
| Rotation | Changes object orientation |
| Scaling | Changes object size |
| Shear | Changes object shape by shifting coordinates |
Rotation, scaling, and shear can be represented using linear transformation matrices when performed relative to the origin.
Translation requires vector addition or homogeneous coordinates.
Linear Transformations
A linear transformation is a function between vector spaces that preserves vector addition and scalar multiplication.
A transformation T is linear when it satisfies two conditions.
Additivity:
T(u + v) = T(u) + T(v)
Homogeneity:
T(cu) = cT(u)
Here, u and v are vectors, while c is a scalar.
Consider the transformation:
T(x, y) = (2x, 3y)
For the vector (2, 4):
T(2, 4) = (4, 12)
The transformation doubles the x-coordinate and triples the y-coordinate.
The corresponding transformation matrix is:
[2 0]
A = [0 3]
Applying the matrix to a column vector gives:
[2 0] [2] [ 4]
[0 3] [4] = [12]
This operation allows computers to transform graphical coordinates through matrix multiplication.
Identity
The identity transformation preserves the original coordinates of every point.
The identity matrix in three dimensions is:
[1 0 0]
I = [0 1 0]
[0 0 1]
Consider the point P = (2, 4, 6).
[1 0 0] [2] [2]
[0 1 0] [4] = [4]
[0 0 1] [6] [6]
The resulting point remains (2, 4, 6).
Graphics programmers often initialize transformation matrices using the identity matrix before applying rotation, scaling, or translation.
The identity matrix represents an object with no transformation applied.
Scale
Scaling changes the size of an object by multiplying its coordinates by selected scale factors.
The scaling matrix in three dimensions is:
[sx 0 0]
S = [ 0 sy 0]
[ 0 0 sz]
Where:
- sx = Scaling factor along the x-axis.
- sy = Scaling factor along the y-axis.
- sz = Scaling factor along the z-axis.
Consider a point:
P = (2, 3, 4)
Apply the scaling factors:
sx = 2, sy = 3, sz = 0.5
[2 0 0 ] [2] [4]
[0 3 0 ] [3] = [9]
[0 0 0.5] [4] [2]
The transformed point is:
P′ = (4, 9, 2)
Scaling has increased the coordinates along the x-axis and y-axis while reducing the coordinate along the z-axis.
There are two main types of scaling.
Uniform scaling uses the same scale factor along every axis and preserves the proportions of an object when the factor is positive.
Non-uniform scaling uses different scale factors along different axes and can change the proportions of an object.
A negative scale factor along one axis produces a reflection across the corresponding coordinate plane.
Rotation
Rotation changes the orientation of an object around a fixed point or axis.
A rotation matrix uses trigonometric functions to calculate new coordinates after an object turns through a given angle.
For a counterclockwise rotation in the Cartesian plane, the rotation matrix is:
[cos θ −sin θ]
R(θ) = [sin θ cos θ]
The angle θ is commonly expressed in radians when working with programming languages and graphics libraries.
Common angle conversions are:
| Degrees | Radians |
|---|---|
| 30° | π/6 |
| 45° | π/4 |
| 60° | π/3 |
| 90° | π/2 |
| 180° | π |
| 360° | 2π |
Rotation matrices preserve distances and angles between points.
A proper rotation matrix satisfies:
RᵀR = I
det(R) = 1
These properties make rotation matrices useful for camera orientation, character animation, and object movement.
Rotate Around the Z Axis
Rotation around the z-axis changes the x-coordinate and y-coordinate while preserving the z-coordinate.
For column vectors in a right-handed coordinate system, the rotation matrix is:
[cos θ −sin θ 0]
Rz(θ) = [sin θ cos θ 0]
[ 0 0 1]
Consider the point:
P = (3, 2, 5)
Rotate the point counterclockwise through 90° around the positive z-axis, as viewed from the positive end of that axis.
Since cos 90° = 0 and sin 90° = 1:
[0 −1 0] [3] [−2]
[1 0 0] [2] = [ 3]
[0 0 1] [5] [ 5]
The new point is:
P′ = (−2, 3, 5)
The z-coordinate remains unchanged.
Rotation around the z-axis is commonly used in 2D games, graphical interfaces, and 3D object orientation.
Rotate Around Any Axis
Three-dimensional objects can rotate around any axis, not only the x-axis, y-axis, or z-axis.
Rodrigues’ rotation formula provides a mathematical method for rotating a vector around an arbitrary axis passing through the origin.
Let k be a unit vector representing the rotation axis and v be the vector being rotated.
The formula is:
v′ = v cos θ + (k × v) sin θ + k(k · v)(1 − cos θ)
The formula combines three mathematical operations:
- Scalar multiplication.
- Cross product.
- Dot product.
Graphics programmers frequently use quaternions to represent rotations around arbitrary axes.
A unit quaternion can represent a three-dimensional rotation using four components.
q = (w, x, y, z)
Quaternions provide a convenient method for interpolating between orientations and help overcome gimbal lock associated with Euler-angle representations.
Animation systems use quaternion interpolation to create smooth camera movement and character rotations.
Shear
A shear transformation changes the shape of an object by shifting its coordinates parallel to an axis.
A horizontal shear matrix in two dimensions is:
[1 k]
H = [0 1]
The transformed coordinates are:
x′ = x + ky
y′ = y
Consider the point:
P = (2, 3)
Apply a shear factor of k = 2.
x′ = 2 + 2(3) = 8
y′ = 3
The resulting point is:
P′ = (8, 3)
A horizontal shear changes the x-coordinate while preserving the y-coordinate.
Shear transformations have applications in text formatting, image distortion, geometric modeling, and special visual effects.
For example, an oblique text effect can be created by applying a horizontal shear to the coordinates of letters.
Affine Geometry
Affine geometry studies geometric properties that remain unchanged under affine transformations.
An affine transformation combines a linear transformation with a translation.
The general form is:
T(v) = Av + b
Where:
- A = Linear transformation matrix.
- v = Original coordinate vector.
- b = Translation vector.
Affine transformations preserve straight lines and parallelism. General affine transformations do not necessarily preserve distances or angles.
Computer graphics uses affine geometry to move, resize, rotate, reflect, and distort objects.
Translation
Translation moves an object from one position to another without changing its shape, size, or orientation.
The translation formula in three dimensions is:
P′ = P + t
In coordinate form:
x′ = x + tx
y′ = y + ty
z′ = z + tz
Consider the point:
P = (2, 4, 6)
Apply the translation vector:
t = (3, −2, 5)
The resulting coordinates are:
P′ = (2 + 3, 4 − 2, 6 + 5)
P′ = (5, 2, 11)
Translation moves the point three units along the positive x-axis, two units along the negative y-axis, and five units along the positive z-axis.
A nonzero translation is not a linear transformation in ordinary Cartesian coordinates since the origin moves to a different point.
Translation as Shear in 4D
Homogeneous coordinates allow translation to be represented using matrix multiplication.
A three-dimensional Cartesian point:
P = (x, y, z)
Can be represented in homogeneous coordinates as:
P = (x, y, z, 1)
The additional coordinate is commonly represented by w.
The homogeneous translation matrix is:
[1 0 0 tx]
T = [0 1 0 ty]
[0 0 1 tz]
[0 0 0 1]
Consider the point (2, 3, 4) and translation vector (5, 2, −1).
[1 0 0 5] [2] [7]
[0 1 0 2] [3] = [5]
[0 0 1 −1] [4] [3]
[0 0 0 1] [1] [1]
The transformed Cartesian point is:
P′ = (7, 5, 3)
The 4 × 4 matrix acts as a linear shear in four-dimensional vector space. Restricting the operation to points with w = 1 produces an ordinary three-dimensional translation.
The fourth homogeneous coordinate does not represent an additional physical spatial dimension in the scene.
Homogeneous coordinates distinguish points from direction vectors:
| Geometric quantity | Homogeneous representation |
|---|---|
| Position | (x, y, z, 1) |
| Direction | (x, y, z, 0) |
A translation affects positions but does not affect direction vectors.
Affine Transformations
An affine transformation in three-dimensional graphics can be represented using a 4 × 4 partitioned matrix.
[ A t ]
M = [ ]
[ 0 1 ]
The matrix contains four components:
- A 3 × 3 matrix representing a linear transformation.
- A 3 × 1 column vector representing translation.
- A 1 × 3 row vector containing zeros.
- A final scalar value of 1.
Consider a transformation that doubles an object’s size and moves the object five units along the x-axis.
[2 0 0 5]
M = [0 2 0 0]
[0 0 2 0]
[0 0 0 1]
Apply the matrix to P = (1, 2, 3, 1).
[2 0 0 5] [1] [7]
[0 2 0 0] [2] = [4]
[0 0 2 0] [3] [6]
[0 0 0 1] [1] [1]
The transformed point is:
P′ = (7, 4, 6)
A single affine transformation matrix can represent multiple graphical operations.
Compositing Transformations
Compositing transformations means combining two or more geometric transformations into a single matrix.
Matrix multiplication satisfies the associative property:
(AB)C = A(BC)
However, matrix multiplication is generally not commutative.
AB ≠ BA
The order of transformations affects the final position of an object.
For column-vector conventions, consider scaling S, rotation R, and translation T.
The combined transformation matrix is:
M = TRS
The transformed point is:
P′ = TRSP
The operations occur from right to left:
- Scale the object.
- Rotate the object.
- Translate the object.
Consider the point P = (1, 2).
First, apply a uniform scaling factor of 2:
P₁ = (2, 4)
Second, rotate the point counterclockwise through 90°:
P₂ = (−4, 2)
Third, translate the point by (5, 3):
P₃ = (1, 5)
The final point is (1, 5).
Changing the order of these transformations generally produces a different result.
Compositing transformations allows graphics engines to calculate a combined matrix and apply that matrix to multiple vertices.
Projection
Projection converts three-dimensional coordinates into a form that can be displayed on a two-dimensional screen.
There are two major types of projection in computer graphics.
| Projection type | Characteristics | Common applications |
|---|---|---|
| Perspective projection | Apparent object size decreases with distance | Video games, realistic animation, virtual reality |
| Orthographic projection | Apparent object size does not depend on distance | Engineering drawings, architectural plans, technical modeling |
Perspective projection creates a visual sense of depth.
Orthographic projection preserves relative dimensions along the viewing plane and does not produce perspective foreshortening.
The View Frustum
The view frustum is the three-dimensional region visible through a virtual perspective camera.
A perspective view frustum normally has six clipping planes:
- Near clipping plane.
- Far clipping plane.
- Left clipping plane.
- Right clipping plane.
- Top clipping plane.
- Bottom clipping plane.
The shape of the view frustum depends on the camera’s field of view, aspect ratio, near clipping distance, and far clipping distance.
For example, a virtual camera may have:
| Camera parameter | Example value |
|---|---|
| Vertical field of view | 60° |
| Aspect ratio | 16:9 |
| Near clipping distance | 0.1 units |
| Far clipping distance | 100 units |
Objects outside the view frustum do not contribute directly to the visible image through ordinary rasterization.
Triangles crossing the frustum boundaries can be clipped so that their visible portions remain available for rendering.
Frustum culling allows graphics engines to skip certain objects outside the visible region before rendering them.
Clip Space and Normalized Device Coordinates
Clip space is the homogeneous coordinate space produced after applying the projection matrix.
A vertex in clip space has four coordinates:
Pclip = (xc, yc, zc, wc)
After clipping, the graphics pipeline performs perspective division.
xndc = xc/wc
yndc = yc/wc
zndc = zc/wc
The resulting coordinates are called Normalized Device Coordinates (NDC).
The conventional NDC ranges depend on the graphics API.
| Graphics API | X range | Y range | Z range |
|---|---|---|---|
| OpenGL, default convention | −1 to 1 | −1 to 1 | −1 to 1 |
| Direct3D | −1 to 1 | −1 to 1 | 0 to 1 |
| Metal | −1 to 1 | −1 to 1 | 0 to 1 |
| Vulkan, default convention | −1 to 1 | −1 to 1 | 0 to 1 |
Graphics APIs can differ in viewport orientation and supported coordinate configuration options.
Clip space and normalized device coordinates are related but distinct. Clipping takes place using homogeneous coordinates before perspective division.
A viewport transformation converts normalized device coordinates into screen coordinates.
For a screen with a width of 1,920 pixels and a height of 1,080 pixels, the center of the normalized coordinate system corresponds to approximately:
(960, 540)
The exact mapping depends on the viewport and pixel-coordinate conventions.
The Projection Matrix
A projection matrix transforms camera-space coordinates into clip-space coordinates.
For a conventional right-handed OpenGL perspective projection using column vectors, the matrix is:
[f/a 0 0 0 ]
P = [ 0 f 0 0 ]
[ 0 0 (F+n)/(n−F) 2Fn/(n−F) ]
[ 0 0 −1 0 ]
Where:
- f = 1/tan(θ/2).
- θ = Vertical field of view.
- a = Aspect ratio.
- n = Near clipping distance.
- F = Far clipping distance.
Projection matrices differ between graphics APIs and coordinate conventions.
A simplified perspective projection illustrates how distance affects apparent object size.
For a camera looking along the positive z-axis:
x′ = fx/z
y′ = fy/z
Consider a point P = (4, 2, 8) with a focal-length parameter of f = 2.
x′ = (2 × 4)/8 = 1
y′ = (2 × 2)/8 = 0.5
The projected point is:
P′ = (1, 0.5)
Move the point farther away to P = (4, 2, 16).
x′ = 0.5
y′ = 0.25
Doubling the depth halves the projected coordinates in this example.
This relationship explains why distant objects appear smaller in perspective rendering.
Conventions
Graphics programming requires consistent conventions for vectors, matrices, coordinate systems, and transformation order.
Two programs can represent the same mathematical transformation using different matrix arrangements.
A developer must know whether a graphics library uses row vectors or column vectors, how matrices are stored, and which coordinate conventions the rendering system expects.
The SIMD Library
Single Instruction, Multiple Data (SIMD) is a computing technique that performs the same type of operation on multiple data elements.
Graphics calculations frequently involve vectors containing two, three, or four components.
SIMD instructions can process multiple vector components together, depending on the hardware and operation.
Apple’s SIMD library provides mathematical types and operations for vectors and matrices used in applications such as Metal graphics programming.
Graphics Processing Units (GPUs) perform large numbers of mathematical operations in parallel during rendering.
NVIDIA’s Compute Unified Device Architecture (CUDA) provides a platform for general-purpose GPU computing, including matrix calculations, scientific computing, and image processing.
SIMD operations and GPU parallel processing help reduce the time required for large graphics workloads.
Matrix Storage
Matrices can be stored in computer memory using two common arrangements:
- Row-major storage.
- Column-major storage.
Consider the matrix:
[1 2 3]
A = [4 5 6]
[7 8 9]
Row-major storage places the rows consecutively in memory:
1, 2, 3, 4, 5, 6, 7, 8, 9
Column-major storage places the columns consecutively in memory:
1, 4, 7, 2, 5, 8, 3, 6, 9
| Property | Row-major | Column-major |
|---|---|---|
| Storage sequence | Row by row | Column by column |
| First three values | 1, 2, 3 | 1, 4, 7 |
| Mathematical matrix | Unchanged | Unchanged |
Matrix storage order and the choice between row-vector and column-vector multiplication are separate conventions.
Graphics programmers must check both conventions when passing transformation matrices between programming languages, graphics libraries, and shaders.
OpenGL Shading Language (GLSL) and High-Level Shading Language (HLSL) provide mathematical operations for graphics programming.
Incorrect matrix interpretation can produce unexpected transformations.
1. Applications in Cryptography
Linear algebra has applications in cryptography through matrix multiplication, modular arithmetic, linear codes, and systems of equations.
The Hill cipher is a classical encryption method that uses matrices to transform groups of letters into encrypted messages.
The general encryption formula is:
C = KP mod 26
Where:
- C = Ciphertext vector.
- K = Encryption key matrix.
- P = Plaintext vector.
Letters are assigned numerical values from 0 to 25.
A = 0, B = 1, C = 2, …, Z = 25
The encryption key must have a modular inverse for decryption to work.
Solved Example: Cryptography
Encrypt the word HI using the following key matrix:
[3 3]
K = [2 5]
Step 1: Convert letters into numbers.
H = 7
I = 8
[7]
P = [8]
Step 2: Multiply the key matrix by the plaintext vector.
[3 3] [7] [45]
[2 5] [8] = [54]
Step 3: Apply modulo 26.
45 mod 26 = 19
54 mod 26 = 2
Step 4: Convert the numbers into letters.
19 = T
2 = C
The encrypted message is:
HI → TC
The Hill cipher demonstrates how linear algebra can transform information using matrix multiplication.
The Hill cipher is not secure enough for modern communication. Contemporary cryptographic systems use more advanced mathematical constructions.
2. Applications in Computed Tomography
Computed Tomography (CT) uses X-ray measurements taken from different directions to reconstruct images of internal body structures.
Linear algebra helps represent the relationship between measured X-ray attenuation and the unknown properties of tissues.
A simplified mathematical model is:
Ax = b
Where:
- A = Matrix representing measurement paths.
- x = Unknown tissue attenuation values.
- b = Measured attenuation data.
Image reconstruction involves estimating the unknown vector x from the available measurements.
Medical imaging systems use mathematical methods such as least squares, iterative reconstruction, and regularization to process measurement data.
Solved Example: Computed Tomography
Consider a simplified educational reconstruction problem involving two unknown attenuation values, x and y.
Suppose two measurements produce the equations:
x + y = 10
2x + y = 14
The matrix representation is:
[1 1] [x] [10]
[2 1] [y] = [14]
Subtract the first equation from the second equation.
2x + y − (x + y) = 14 − 10
x = 4
Substitute x = 4 into the first equation.
4 + y = 10
y = 6
Therefore:
x = 4 and y = 6
This example demonstrates how a system of linear equations can recover unknown values from measured information.
Real CT scanners process much larger datasets and use more detailed physical and mathematical models.
3. Applications in Computer Graphics
Linear algebra allows computers to represent graphical objects as collections of vertices and transform those vertices using matrices.
Consider a triangle with vertices:
A = (1, 1)
B = (4, 1)
C = (2, 3)
The coordinates can be stored in a data matrix.
[1 4 2]
V = [1 1 3]
Each column represents a vertex.
Multiplying a transformation matrix by V applies the transformation to all three vertices.
This approach is useful when processing graphical models containing thousands or millions of vertices.
a. Translation
Translation changes the position of a graphical object without changing its size or orientation.
For a two-dimensional point:
x′ = x + tx
y′ = y + ty
The homogeneous translation matrix is:
[1 0 tx]
T = [0 1 ty]
[0 0 1]
Translation is used to move game characters, reposition graphical elements, and place objects within virtual environments.
b. Rotation
Rotation changes the orientation of an object around a fixed point.
The two-dimensional rotation matrix is:
[cos θ −sin θ]
R = [sin θ cos θ]
The transformed coordinates are:
x′ = x cos θ − y sin θ
y′ = x sin θ + y cos θ
Rotation is used in animation, camera movement, game development, robotics, and computer-aided design.
To rotate an object around a point other than the origin, translate the rotation center to the origin, perform the rotation, and translate the center back to its original position.
c. Scaling
Scaling changes the dimensions of an object.
The two-dimensional scaling matrix is:
[sx 0]
S = [ 0 sy]
The transformed coordinates are:
x′ = sx × x
y′ = sy × y
Scaling is used to resize images, adjust graphical models, control object dimensions, and create zoom-related effects.
Solved Examples
The following examples demonstrate translation, scaling, and rotation using the same triangle.
The original vertices are:
A = (1, 1)
B = (4, 1)
C = (2, 3)
Each example starts with the original triangle.
Example for Translation
Translate the triangle three units along the positive x-axis and two units along the positive y-axis.
The translation vector is:
t = (3, 2)
The homogeneous translation matrix is:
[1 0 3]
T = [0 1 2]
[0 0 1]
Solution
Apply the translation formula to each vertex.
A′ = (1 + 3, 1 + 2) = (4, 3)
B′ = (4 + 3, 1 + 2) = (7, 3)
C′ = (2 + 3, 3 + 2) = (5, 5)
| Vertex | Original coordinates | Translated coordinates |
|---|---|---|
| A | (1, 1) | (4, 3) |
| B | (4, 1) | (7, 3) |
| C | (2, 3) | (5, 5) |
The translated triangle has the same shape and dimensions as the original triangle.
Only its position has changed.
Example for Scaling
Scale the original triangle by a factor of 2 along both axes relative to the origin.
The scaling matrix is:
[2 0]
S = [0 2]
The original data matrix is:
[1 4 2]
V = [1 1 3]
Multiply the scaling matrix by the data matrix.
[2 0] [1 4 2] [2 8 4]
[0 2] [1 1 3] = [2 2 6]
The new coordinates are:
A′ = (2, 2)
B′ = (8, 2)
C′ = (4, 6)
| Vertex | Original coordinates | Scaled coordinates |
|---|---|---|
| A | (1, 1) | (2, 2) |
| B | (4, 1) | (8, 2) |
| C | (2, 3) | (4, 6) |
Every side length doubles. The area becomes four times the original area.
The triangle’s proportions remain unchanged.
Example for Rotation
Rotate the original triangle counterclockwise through 90° around the origin.
The rotation matrix is:
[0 −1]
R = [1 0]
Multiply the rotation matrix by the original data matrix.
[0 −1] [1 4 2] [−1 −1 −3]
[1 0] [1 1 3] = [ 1 4 2]
The resulting coordinates are:
A′ = (−1, 1)
B′ = (−1, 4)
C′ = (−3, 2)
| Vertex | Original coordinates | Rotated coordinates |
|---|---|---|
| A | (1, 1) | (−1, 1) |
| B | (4, 1) | (−1, 4) |
| C | (2, 3) | (−3, 2) |
The triangle has rotated through 90° without changing its side lengths or area.
4. Applications in Graph Theory
Graph theory studies relationships between objects represented by vertices and edges.
Linear algebra provides matrix-based methods for representing graphs and analyzing their connections.
An adjacency matrix records whether two vertices are connected.
Consider a graph with three vertices:
A, B, and C.
Suppose A connects to B, and B connects to C.
The adjacency matrix is:
[0 1 0]
M = [1 0 1]
[0 1 0]
A value of 1 represents a connection. A value of 0 represents the absence of a connection.
Adjacency matrices have applications in:
- Social network analysis.
- Computer network design.
- Transportation planning.
- Game navigation.
- Search engine algorithms.
- Recommendation systems.
Graphics engines use graph structures to represent relationships between objects, animation components, and connected regions.
Two-Step and Three-Step System
Matrix multiplication allows computers to calculate the number of walks between graph vertices.
The entries of M² represent the number of walks of length two.
Using the previous adjacency matrix:
[1 0 1]
M² = [0 2 0]
[1 0 1]
The entry in the first row and third column is 1.
There is one two-step walk from A to C:
A → B → C
The entries of M³ represent the number of walks of length three.
[0 2 0]
M³ = [2 0 2]
[0 2 0]
There are two three-step walks from A to B:
A → B → A → B
A → B → C → B
Matrix powers help analyze connectivity and movement through networks.
A walk may revisit vertices or edges. Matrix powers do not necessarily count only simple paths.
5. Applications in Electrical Circuits
Linear algebra helps electrical engineers calculate unknown currents and voltages in electrical circuits.
Kirchhoff’s circuit laws produce systems of linear equations that can be solved using matrices.
Consider a simplified two-loop resistive circuit with the following mesh-current equations:
4I₁ − 2I₂ = 10
−2I₁ + 6I₂ = 4
The matrix representation is:
[ 4 −2] [I₁] [10]
[−2 6] [I₂] = [ 4]
Multiply the first equation by 3.
12I₁ − 6I₂ = 30
Add the second equation.
10I₁ = 34
I₁ = 3.4 amperes
Substitute I₁ = 3.4 into the first equation.
4(3.4) − 2I₂ = 10
13.6 − 2I₂ = 10
I₂ = 1.8 amperes
The resulting mesh currents are:
I₁ = 3.4 A and I₂ = 1.8 A
Linear algebra provides an organized method for solving circuit equations involving multiple electrical components.
Computer engineering uses similar matrix-based techniques in circuit simulation, signal processing, and electronic system design.
Other Applications of Linear Algebra in Computer Graphics
Translation, rotation, scaling, and projection are basic graphics operations. Advanced rendering systems use several other linear algebra techniques.
Dot Product in Lighting and Shading
The dot product measures the relationship between two vectors.
For vectors a and b:
a · b = aₓbₓ + aᵧbᵧ + azbz
Graphics systems use dot products to calculate how directly light strikes a surface.
A simplified Lambertian diffuse lighting model uses:
I = Id max(0, n · l)
Where:
- I = Calculated diffuse light intensity.
- Id = Diffuse lighting coefficient incorporating light intensity.
- n = Unit surface normal vector.
- l = Unit vector pointing toward the light source.
Consider:
n = (0, 0, 1)
l = (0, 0.6, 0.8)
The dot product is:
n · l = 0.8
The angular lighting factor is 0.8, or 80% of its maximum value.
When the light direction is perpendicular to the surface normal, the dot product becomes zero.
This calculation helps produce visible differences between illuminated and shaded surfaces.
Cross Product and Surface Normals
The cross product produces a vector perpendicular to two nonparallel vectors in three-dimensional space.
Consider:
a = (1, 0, 0)
b = (0, 1, 0)
Their cross product is:
a × b = (0, 0, 1)
Graphics programmers use cross products to calculate normal vectors for triangular surfaces.
A surface normal describes the orientation of a surface and helps determine lighting, visibility, and reflection.
When an object undergoes non-uniform scaling, its normal vectors generally require transformation using the inverse transpose of the linear transformation matrix, provided that matrix is invertible.
Linear Algebra in Ray Tracing
Ray tracing calculates how light rays interact with objects in a three-dimensional scene.
A ray is represented mathematically as:
r(t) = o + td
Where:
- o = Ray origin.
- d = Ray direction.
- t = Distance parameter when d is a unit vector.
Ray tracing uses vector operations and systems of equations to calculate intersections between rays and objects.
Consider a ray:
o = (0, 0, 0)
d = (0, 0, 1)
A plane lies at z = 5.
The ray intersects the plane when:
t = 5
The intersection point is:
r(5) = (0, 0, 5)
Ray-tracing algorithms use similar calculations to determine visibility, shadows, reflections, and refractions.
Linear Algebra in Animation
Computer animation uses mathematical transformations to calculate changes in object positions and orientations over time.
Linear interpolation calculates intermediate values between two positions.
The interpolation formula is:
P(t) = (1 − t)A + tB
Where t ranges from 0 to 1.
Consider an object moving from:
A = (0, 0)
B = (10, 20)
At t = 0.5:
P(0.5) = 0.5(0, 0) + 0.5(10, 20)
P(0.5) = (5, 10)
The object reaches the midpoint of its movement.
Animation software uses interpolation to calculate intermediate positions between keyframes.
Quaternion interpolation provides smoother orientation changes than directly interpolating individual rotation matrix entries in many situations.
Eigenvalues and Eigenvectors in Computer Graphics
Eigenvectors describe directions that remain aligned with themselves after a linear transformation.
The mathematical relationship is:
Av = λv
Where:
- A = Transformation matrix.
- v = Nonzero eigenvector.
- λ = Corresponding eigenvalue.
Eigenvalues and eigenvectors have applications in shape analysis, mesh processing, deformation, and Principal Component Analysis (PCA).
PCA identifies important directions of variation in a dataset.
For example, graphics software can analyze the covariance matrix of a collection of three-dimensional points to estimate the principal directions of a geometric shape.
Singular Value Decomposition
Singular Value Decomposition (SVD) expresses a matrix as a product of three matrices.
A = UΣVᵀ
The matrices U and V contain orthonormal singular vectors. The matrix Σ contains nonnegative singular values.
SVD has applications in:
- Image compression.
- Shape analysis.
- Matrix approximation.
- Geometric alignment.
- Mesh deformation.
A digital grayscale image can be represented as a matrix of pixel intensities.
Keeping only the largest singular values produces a lower-rank approximation of the original image.
For a grayscale image containing 1,000 × 1,000 pixels, the original matrix contains 1,000,000 numerical entries.
A rank-50 SVD approximation requires approximately:
1,000 × 50 + 50 + 50 × 1,000 = 100,050 entries
This represents about 90% fewer numerical entries before considering storage formats and metadata.
Image quality depends on how much visual information the retained singular values capture.
Barycentric Coordinates and Texture Mapping
Barycentric coordinates represent a point within a triangle using weighted combinations of its vertices.
For triangle vertices A, B, and C:
P = αA + βB + γC
Where:
α + β + γ = 1
For a point inside the triangle, the weights are nonnegative.
Graphics systems use barycentric coordinates to interpolate colors, texture coordinates, and other vertex attributes.
Perspective-correct interpolation accounts for the homogeneous depth-related coordinate when interpolating suitable attributes during perspective rendering.
Texture mapping uses these calculations to apply images to three-dimensional surfaces.
Determinants in Graphics Transformations
The determinant of a transformation matrix provides information about changes in area, volume, and orientation.
For a two-dimensional scaling matrix:
[2 0]
A = [0 3]
The determinant is:
det(A) = 2 × 3 = 6
The transformed area is six times the original area.
A negative determinant indicates that a nonsingular linear transformation reverses orientation.
A zero determinant indicates that the transformation is singular and collapses at least one spatial direction.
Graphics programmers use determinant calculations when analyzing transformations and orientation changes.
Applications of Linear Algebra in Computer Programming
Programming languages and mathematical libraries allow developers to implement linear algebra operations directly.
Python provides numerical computing libraries such as NumPy for working with vectors and matrices.
The following program rotates a triangle through 90° around the origin.
import numpy as np
# Original triangle vertices
vertices = np.array([
[1, 4, 2],
[1, 1, 3]
])
# Counterclockwise rotation angle
theta = np.radians(90)
# Rotation matrix
rotation = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
]) # Apply rotation rotated_vertices = rotation @ vertices print(“Original vertices:”) print(vertices) print(“Rotated vertices:”) print(np.round(rotated_vertices, 2))
Expected output:
Original vertices:
[[1 4 2]
[1 1 3]]
Rotated vertices:
[[-1. -1. -3.]
[ 1. 4. 2.]]
The program applies matrix multiplication to all three vertices.
Python provides a convenient environment for learning mathematical graphics operations before working with larger graphics engines.
Applications of Linear Algebra in Computer Science and Engineering
Linear algebra supports several areas of computer science and engineering beyond graphics.
| Field | Application |
|---|---|
| Artificial intelligence | Neural network calculations |
| Machine learning | Feature representation and optimization |
| Data science | Regression and dimensionality reduction |
| Computer vision | Image transformations and camera calibration |
| Robotics | Position and orientation calculations |
| Electrical engineering | Circuit analysis |
| Signal processing | Filtering and signal representation |
| Civil engineering | Structural analysis |
| Computer graphics | Rendering and animation |
| Cryptography | Mathematical encryption structures |
| Network analysis | Adjacency matrices and connectivity |
| Scientific computing | Numerical solutions to mathematical models |
Artificial Intelligence (AI) and Machine Learning (ML) systems frequently represent datasets using matrices.
Neural networks perform matrix multiplication to calculate relationships between input features, weights, and output values.
Computer vision uses coordinate transformations to estimate object positions and reconstruct three-dimensional scenes from images.
Engineering applications use linear systems and matrix decompositions to solve practical mathematical problems.
The Model-View-Projection Pipeline
The Model-View-Projection (MVP) pipeline transforms an object’s local coordinates into clip-space coordinates.
The general formula for column vectors is:
Pclip = PVMPlocal
Where:
- M = Model matrix.
- V = View matrix.
- P = Projection matrix.
- Plocal = Original vertex coordinates.
The model matrix places an object within the world.
The view matrix transforms world coordinates into the camera’s coordinate system.
The projection matrix transforms camera-space coordinates into clip space.
| Coordinate stage | Purpose |
|---|---|
| Local space | Represents coordinates relative to the object |
| World space | Places the object within the scene |
| View space | Represents coordinates relative to the camera |
| Clip space | Prepares coordinates for clipping |
| Normalized device coordinates | Represents coordinates after perspective division |
| Screen space | Converts coordinates into viewport positions |
The MVP pipeline is widely used in rasterization-based three-dimensional graphics.
Frequently Asked Questions
What are the applications of linear algebra in computer graphics?
The applications of linear algebra in computer graphics include object translation, rotation, scaling, shearing, camera positioning, perspective projection, lighting, shading, animation, texture mapping, and ray tracing.
Why is linear algebra important in computer graphics?
Linear algebra provides mathematical methods for representing graphical objects and transforming their coordinates. Matrices and vectors allow computers to process large collections of vertices using organized calculations.
How are matrices used in computer graphics?
Matrices represent geometric transformations such as rotation, scaling, shear, translation in homogeneous coordinates, and projection. Multiplying a transformation matrix by a coordinate vector produces transformed coordinates.
What is a transformation matrix?
A transformation matrix is a matrix that represents a mathematical operation applied to vectors or coordinates. Graphics applications use transformation matrices to change object positions, sizes, orientations, and coordinate frames.
Why are 4 × 4 matrices used in 3D graphics?
Four-by-four matrices allow three-dimensional graphics systems to represent translation, rotation, scaling, shear, and projection using homogeneous coordinates and matrix multiplication.
Is translation a linear transformation?
No, a nonzero translation is not a linear transformation in ordinary Cartesian coordinates. Translation moves the origin, while every linear transformation maps the zero vector to itself.
Translation can be represented using a linear matrix operation in a higher-dimensional homogeneous coordinate representation.
What is the difference between affine and linear transformations?
A linear transformation preserves vector addition, scalar multiplication, and the origin.
An affine transformation combines a linear transformation with a translation and can move the origin to another point.
How is linear algebra used in video games?
Video games use linear algebra for character movement, camera positioning, object rotation, collision calculations, lighting, animation, and three-dimensional rendering.
How is linear algebra used in computer engineering?
Computer engineering uses linear algebra in circuit analysis, signal processing, robotics, image processing, computer architecture, and numerical simulations.
What is the difference between perspective and orthographic projection?
Perspective projection changes the apparent size of objects based on their distance from the camera. Orthographic projection preserves apparent dimensions independently of depth.
Do graphics programmers need linear algebra?
Yes, graphics programmers benefit from learning linear algebra. Vectors, matrices, coordinate transformations, dot products, cross products, and projection matrices form the mathematical foundation of graphics programming.
Is linear algebra used in Blender and Unity?
Yes, Blender and Unity use linear algebra to represent and transform objects, calculate camera orientation, animate models, and process graphical scenes.
Where can students find linear algebra applications in PDF or PPT format?
Students can find educational lecture notes, textbooks, and presentation slides through university websites and open educational resources. Topics worth studying include transformation matrices, vector spaces, homogeneous coordinates, projection, and matrix multiplication.
Conclusion
The applications of linear algebra in computer graphics include representing objects, changing their positions, rotating shapes, adjusting their sizes, and converting three-dimensional scenes into two-dimensional images.
Vectors, matrices, coordinate systems, affine geometry, and projection matrices provide mathematical methods for processing graphical information.
Computer graphics uses these methods in video games, animation, digital design, camera systems, lighting, and realistic rendering.
Linear algebra has further applications in cryptography, computed tomography, graph theory, electrical circuits, artificial intelligence, and computer programming.
Learning linear algebra through practical examples helps students connect mathematical formulas with real computer science applications. A strong foundation in vectors and matrices makes advanced topics such as three-dimensional graphics, machine learning, and computational engineering easier to study.
MathZon encourages students to explore mathematical concepts through solved problems, practical applications, and clear explanations.
References and Further Reading
- Metal by Example. Linear Algebra for Graphics Programming. https://metalbyexample.com/linear-algebra/
- Ohio State University, Ximera. Application to Computer Graphics. https://ximera.osu.edu/oerlinalg/LinearAlgebra/APP-0040/main
- Strang, Gilbert. Introduction to Linear Algebra. Wellesley-Cambridge Press.
- Lay, David C., Steven R. Lay, and Judi J. McDonald. Linear Algebra and Its Applications. Pearson.
- Hughes, John F., et al. Computer Graphics: Principles and Practice. Third Edition. Addison-Wesley.
- Akenine-Möller, Tomas, et al. Real-Time Rendering. Fourth Edition. CRC Press.
- Shirley, Peter, and Steve Marschner. Fundamentals of Computer Graphics.
- Khronos Group. OpenGL Documentation. https://www.khronos.org/opengl/
- Apple Developer Documentation. Metal. https://developer.apple.com/metal/
- NumPy Documentation. https://numpy.org/doc/
Explore More Mathematics on MathZon
Continue learning mathematics through related educational topics:
- Why Is Math So Important?
- The Role of Mathematics in Technology Advancements
- How to Develop Strong Problem-Solving Skills in Mathematics
- The Power of Prime Numbers
- Applications of Graph Theory in Transportation Planning
- Mathematical Models in Economics
- Introduction to Matrices and Determinants
- Applications of Mathematics in Computer Science
Visit MathZon for more mathematical explanations, solved examples, and real-world applications.