MATH-125 · Lesson 8 of 12 · 30 min

Linear transformations and geometry

So far a matrix has mostly been a table of coefficients in a system of equations. A matrix can also be understood as a machine that transforms vectors: it takes an input vector and produces an output vector, rotating, stretching, reflecting, shearing or projecting it. This point of view explains why matrix multiplication is defined the way it is, what determinants measure, and why eigenvectors (Lesson 9) matter. It is also the working language of computer graphics, robotics, computer-aided design, surveying and the mechanics of deformable materials, where points and directions are constantly rotated, scaled and moved between coordinate systems. This lesson introduces linear transformations, shows how to find the matrix of a transformation from what it does to the basis vectors, catalogs the basic geometric transformations, explains composition and inverses, and shows how homogeneous coordinates bring translations into the same framework.

Linear transformations

A transformation \(T\) from \(\mathbb{R}^n\) to \(\mathbb{R}^m\) assigns to each input vector \(\mathbf{x}\) an output \(T(\mathbf{x})\). It is linear if it respects addition and scaling:

\[T(\mathbf{u} + \mathbf{v}) = T(\mathbf{u}) + T(\mathbf{v}), \qquad T(c\mathbf{u}) = c\,T(\mathbf{u})\]

Every matrix defines a linear transformation, \(T(\mathbf{x}) = A\mathbf{x}\), because matrix multiplication has these properties (Lesson 4). Conversely, every linear transformation between spaces of these kinds is multiplication by some matrix. Linear transformations always send the origin to the origin, straight lines to straight lines (or to points), and parallel lines to parallel lines, so they turn grids of squares into grids of parallelograms.

Many physical relationships are linear, at least approximately: the displacement of an elastic structure as a function of the loads, the outputs of a circuit as functions of its inputs, the strain in a material as a function of small deformations. The linear transformation framework applies to all of them.

The matrix of a transformation

A linear transformation is completely determined by what it does to the standard basis vectors \(\mathbf{e}_1, \ldots, \mathbf{e}_n\), because every vector is a combination of them and \(T\) preserves combinations. The matrix of \(T\) has the images of the basis vectors as its columns:

\[A = \begin{pmatrix} T(\mathbf{e}_1) & T(\mathbf{e}_2) & \cdots & T(\mathbf{e}_n) \end{pmatrix}\]

This gives a practical recipe: to find the matrix of a geometric transformation, work out where it sends each unit vector along the axes, and write those images as columns.

Worked problem

The rotation matrix

Find the matrix that rotates vectors in the plane counterclockwise by an angle \(\theta\), and use it to rotate \((3, 1)\) by 90°.

Show solution
  1. Rotating \(\mathbf{e}_1 = (1, 0)\) by \(\theta\) gives \((\cos\theta, \sin\theta)\); rotating \(\mathbf{e}_2 = (0, 1)\) gives \((-\sin\theta, \cos\theta)\).
  2. \[R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}\]
  3. For 90°: \(R = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}\), so \(R(3, 1) = (-1, 3)\).

Answer: R(90°) sends (3, 1) to (−1, 3), which has the same length, √10, and is perpendicular to the original, as a rotation should be.

A catalog of plane transformations

Basic linear transformations of the plane.
TransformationMatrixEffect on the unit squareDeterminant
Rotation by θ\(\begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}\)Rotated square1
Scaling\(\begin{pmatrix} s_x & 0 \\ 0 & s_y \end{pmatrix}\)Rectangle \(s_x \times s_y\)\(s_x s_y\)
Reflection in the x-axis\(\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\)Flipped square−1
Horizontal shear\(\begin{pmatrix} 1 & k \\ 0 & 1 \end{pmatrix}\)Parallelogram leaning sideways1
Projection onto the x-axis\(\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}\)Collapsed to a segment0

The determinant has a clear geometric meaning (Lesson 6): its absolute value is the factor by which the transformation scales areas (volumes in three dimensions), and its sign tells whether orientation is preserved (positive) or reversed, as in a reflection (negative). Rotations and shears preserve area; a projection flattens everything onto a line, so its determinant is zero and it cannot be undone.

Four panels, each showing the unit square in light gray and its image under a transformation in color. The first panel shows the square rotated by 30 degrees. The second shows it stretched into a rectangle twice as wide. The third shows a horizontal shear turning it into a parallelogram leaning to the right. The fourth shows a reflection flipping it below the x-axis.
The unit square under a rotation, a scaling, a shear and a reflection.

Worked problem

Simple shear of a material

In a simple shear test, a square block of rubber is deformed so that each point moves horizontally by 0.3 times its height: \((x, y) \mapsto (x + 0.3y, y)\). Find the matrix, the change in area, and the new angle at the bottom-left corner.

Show solution
  1. Matrix: \(\begin{pmatrix} 1 & 0.3 \\ 0 & 1 \end{pmatrix}\), with determinant 1, so the area is unchanged.
  2. The vertical edge \((0, 1)\) becomes \((0.3, 1)\), which makes an angle \(\arctan(1/0.3) = 73.3°\) with the horizontal.
  3. The corner angle has decreased from 90° by \(\arctan 0.3 = 16.7°\), which is the shear strain \(\gamma = 0.3\) rad expressed as an angle.

Answer: Area is preserved and the right angle closes by 16.7°. Shear strain, the change in a right angle, is a central quantity in the mechanics of materials, and deformation gradients like this matrix describe how materials deform in finite element analysis.

Projection onto a line

The projection of a vector \(\mathbf{x}\) onto the line through the origin in the direction of a unit vector \(\mathbf{u}\) is \((\mathbf{u}\cdot\mathbf{x})\mathbf{u}\) (Lesson 1). In matrix form this is \(P\mathbf{x}\) with \(P = \mathbf{u}\mathbf{u}^T\), a symmetric matrix satisfying \(P^2 = P\): projecting twice is the same as projecting once. Projections are the basis of least squares (Lesson 10), where a measurement vector is projected onto the set of values a model can produce.

Composition and the order of operations

Applying one transformation after another is called composition. If \(\mathbf{x}\) is transformed first by \(B\) and then by \(A\), the result is \(A(B\mathbf{x}) = (AB)\mathbf{x}\): the matrix of the composition is the product \(AB\), with the first transformation on the right. This is the reason matrix multiplication is defined row-by-column (Lesson 4): it is exactly the rule that makes products represent compositions.

Because matrix multiplication is not commutative, order matters. Rotating and then shearing a figure generally gives a different result from shearing and then rotating it. Rotations about the same axis do commute (\(R(\alpha)R(\beta) = R(\alpha + \beta)\), which proves the angle addition formulas of trigonometry in one line), but three-dimensional rotations about different axes do not, a fact that matters in aircraft attitude, robot joints and camera orientation.

Worked problem

Order matters

Compare reflecting in the x-axis then rotating by 90°, with rotating by 90° then reflecting, applied to \((1, 0)\).

Show solution
  1. Reflect first: \(F = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\), \(R = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}\). Then \(RF = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\), and \(RF(1, 0) = (0, 1)\).
  2. Rotate first: \(FR = \begin{pmatrix} 0 & -1 \\ -1 & 0 \end{pmatrix}\), and \(FR(1, 0) = (0, -1)\).

Answer: The results differ: (0, 1) versus (0, −1). RF is a reflection in the line y = x, while FR is a reflection in the line y = −x.

Inverse transformations

A transformation can be undone exactly when its matrix is invertible (determinant non-zero, Lesson 6). The inverse of a rotation by \(\theta\) is the rotation by \(-\theta\), and because \(\cos(-\theta) = \cos\theta\) and \(\sin(-\theta) = -\sin\theta\), this is simply the transpose: \(R^{-1} = R^T\). Matrices with this property, \(Q^TQ = I\), are called orthogonal matrices; their columns are perpendicular unit vectors, and they represent rotations and reflections, which preserve lengths and angles. Their inverses cost nothing to compute, a fact used constantly in graphics and robotics. The inverse of a shear by \(k\) is a shear by \(-k\); the inverse of a scaling by \(s\) is a scaling by \(1/s\); a projection has no inverse.

Rotations in three dimensions

In three dimensions, rotation by \(\theta\) about the \(z\)-axis leaves \(z\) unchanged and rotates \(x\) and \(y\) as in the plane:

\[R_z(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{pmatrix}\]

with similar matrices \(R_x\) and \(R_y\) for the other axes. Any orientation of a rigid body can be reached by three successive rotations about chosen axes, for example yaw, pitch and roll for an aircraft or a drone. Because these rotations do not commute, the convention for their order must be stated precisely, and mixing conventions is a classic source of errors in navigation and robotics software. Some applications use quaternions, an extension of complex numbers, to represent rotations without the singularities that angle sequences can suffer.

Homogeneous coordinates and translation

A translation, moving every point by a fixed vector \(\mathbf{t}\), is not linear, since it moves the origin. Yet rotations and translations must be combined constantly, for instance to describe the position of a robot gripper relative to the robot's base. The trick is to add an extra coordinate equal to 1, writing the point \((x, y)\) as \((x, y, 1)\). Then a rotation followed by a translation becomes a single matrix multiplication:

\[\begin{pmatrix} x' \\ y' \\ 1 \end{pmatrix} = \begin{pmatrix} \cos\theta & -\sin\theta & t_x \\ \sin\theta & \cos\theta & t_y \\ 0 & 0 & 1 \end{pmatrix}\begin{pmatrix} x \\ y \\ 1 \end{pmatrix}\]

Sequences of rotations and translations are then composed by multiplying such matrices, exactly as for linear transformations. Graphics processors perform billions of \(4 \times 4\) homogeneous transformations per second to place objects in a scene and project them onto the screen, and robot controllers chain one such matrix per joint to find where the end of the arm is.

Worked problem

A two-link robot arm

A planar robot arm has a first link of length 0.5 m from the base joint and a second link of length 0.3 m. The first joint is at 30° and the second joint bends a further 45°. Find the position of the end of the arm.

Show solution
  1. The first link ends at \(0.5(\cos 30°, \sin 30°) = (0.433, 0.250)\).
  2. The second link points at \(30° + 45° = 75°\), adding \(0.3(\cos 75°, \sin 75°) = (0.078, 0.290)\).
  3. End position: \((0.433 + 0.078, 0.250 + 0.290) = (0.511, 0.540)\) m.

Answer: The gripper is at about (0.511, 0.540) m. In homogeneous form, the same result is the product of two rotation-and-translation matrices applied to the origin of the gripper; for arms with six joints, the same chain of matrices gives the forward kinematics, and solving it backward (inverse kinematics) tells the controller what joint angles reach a desired position.

Changing coordinate systems

Engineers constantly move between coordinate systems: a survey grid and a building grid rotated relative to it, a sensor mounted at an angle on a vehicle, the local axes of a beam element and the global axes of the structure that contains it. If the columns of a matrix \(B\) are the new basis vectors written in the old coordinates, then a vector with new coordinates \(\mathbf{c}\) has old coordinates \(\mathbf{x} = B\mathbf{c}\), and conversely \(\mathbf{c} = B^{-1}\mathbf{x}\). When the new basis is orthonormal, as it is for rotated axes, \(B\) is orthogonal and \(B^{-1} = B^T\), so converting coordinates costs only a transpose. A transformation with matrix \(A\) in the old coordinates has matrix \(B^{-1}AB\) in the new ones, which is how the stiffness matrix of a sloping truss member, simple in the member's own axes, is rotated into the global axes of the structure before assembly (Lesson 12).

Common mistakes

  • MistakeWriting the images of the basis vectors as rows of the matrix.

    InsteadThe images form the columns.

  • MistakeApplying the product AB as "A first, then B".

    InsteadIn (AB)x, B acts first; the rightmost matrix acts first.

  • MistakeAssuming 3D rotations commute.

    InsteadRotations about different axes do not commute; state the order convention.

  • MistakeTreating translation as a linear transformation.

    InsteadUse homogeneous coordinates to combine translation with linear maps.

  • MistakeComputing the inverse of a rotation matrix by elimination.

    InsteadFor orthogonal matrices, the inverse is the transpose.

Summary and key terms

  • A linear transformation respects addition and scaling; every matrix defines one.
  • The columns of a transformation's matrix are the images of the standard basis vectors.
  • Rotations, scalings, reflections, shears and projections have simple matrices.
  • The determinant is the area or volume scale factor; negative means orientation is reversed.
  • Composition corresponds to matrix multiplication, with the first transformation on the right; order matters.
  • Orthogonal matrices (rotations, reflections) have inverse equal to transpose.
  • Homogeneous coordinates combine rotations and translations for graphics and robotics.
Linear transformation
A map that preserves vector addition and scalar multiplication.
Rotation matrix
A matrix that turns vectors through a fixed angle.
Shear
A transformation that slides layers parallel to an axis.
Projection
A transformation that maps vectors onto a line or plane, with P² = P.
Composition
Applying one transformation after another.
Orthogonal matrix
A square matrix with QᵀQ = I, preserving lengths and angles.
Shear strain
The change in a right angle due to deformation.
Homogeneous coordinates
Coordinates with an extra component allowing translations as matrix products.
Forward kinematics
Computing a robot's end position from its joint angles.
Quaternion
A four-component number system used to represent 3D rotations.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Find the matrix that doubles x and leaves y unchanged.

    Show answer

    [[2, 0], [0, 1]].

  2. Rotate (2, 0) by 60°.

    Show answer

    (1, √3).

  3. What is the determinant of a rotation matrix?

    Show answer

    1.

  4. A transformation has determinant −3. What does it do to areas and orientation?

    Show answer

    Triples areas and reverses orientation.

  5. Find the matrix of projection onto the line y = x.

    Show answer

    ½[[1, 1], [1, 1]].

  6. Show that R(α)R(β) = R(α + β) gives the angle addition formula for cosine.

    Show answer

    The top-left entry gives cos α cos β − sin α sin β = cos(α + β).

  7. Inverse of the shear [[1, 2], [0, 1]]?

    Show answer

    [[1, −2], [0, 1]].

  8. Write the homogeneous matrix that translates by (3, −1) without rotation.

    Show answer

    [[1, 0, 3], [0, 1, −1], [0, 0, 1]].

  9. Two-link arm with links 1 m and 1 m, joints at 0° and 90°. End position?

    Show answer

    (1, 1).

  10. Why must the order of yaw, pitch and roll be specified?

    Show answer

    Rotations about different axes do not commute.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz