Tutorials › Linear Algebra › Homogeneous Coordinates for Graphics Transformations

Applications in Networks, Economics and Data · Tutorial 955 of 1000

Homogeneous Coordinates for Graphics Transformations

Represent common two-dimensional graphics transformations with homogeneous-coordinate matrices and compute their effects on points.

Intermediate 9 min read

What You'll Learn

  • Encode a point in the plane as a column with a third, homogeneous coordinate.
  • Read the translation entries in a homogeneous-coordinate matrix.
  • Apply a counterclockwise rotation matrix to a sample point.
  • Represent independent horizontal and vertical scalings.
  • Distinguish two common shears by which coordinate they change.
  • Check a transformed point by multiplying the matrix and interpreting the result.

Why Add a Third Coordinate?

A two-dimensional point is usually recorded as a pair \((x,y)\). A rotation, scaling, or shear about the origin can be written as a \(2\times2\) matrix acting on the column \(\begin{bmatrix}x\\y\end{bmatrix}\). A translation is different: it adds a fixed vector, such as \(\begin{bmatrix}a\\b\end{bmatrix}\), rather than multiplying the point by a \(2\times2\) matrix. Homogeneous coordinates give translations and the other transformations a common matrix representation. That makes each one usable in the same matrix-based graphics workflow.

Throughout, points lie in \(\mathbb{R}^2\), and their coordinates are columns. We represent a point \((x,y)\) by appending a third coordinate equal to \(1\). This extra coordinate is not a new spatial direction: for the transformations studied here, the first two entries give the plane coordinates and the last entry remains \(1\).

Definition: The homogeneous-coordinate vector of a point \((x,y)\in\mathbb{R}^2\) is \(\begin{bmatrix}x\\y\\1\end{bmatrix}\). To recover the point from this vector, read its first two entries. More generally, a triple \(\begin{bmatrix}X\\Y\\w\end{bmatrix}\) with \(w\ne0\) represents the point \((X/w,Y/w)\); in this tutorial, the transformations are applied to triples with \(w=1\) and return triples with \(w=1\).

The convention of using columns determines where the entries go in a transformation matrix. We multiply the matrix on the left of the homogeneous-coordinate column. Translation terms therefore appear in the last column, while the upper-left \(2\times2\) block describes how the original \(x\)- and \(y\)-coordinates contribute to the new coordinates.

Translation as a Matrix

A translation by \((a,b)\) sends \((x,y)\) to \((x+a,y+b)\). In ordinary two-coordinate form, this requires addition. In homogeneous coordinates, the constant terms can instead multiply the final coordinate, which equals \(1\): \(a\cdot1=a\) and \(b\cdot1=b\).

Definition: The homogeneous-coordinate matrix for translation by \((a,b)\in\mathbb{R}^2\) is \(\begin{bmatrix}1&0&a\\0&1&b\\0&0&1\end{bmatrix}\). It acts on a point column \(\begin{bmatrix}x\\y\\1\end{bmatrix}\) to produce \(\begin{bmatrix}x+a\\y+b\\1\end{bmatrix}\).

Worked Example: Translating a Point

Translate the point \((-2,1)\) by \((3,-4)\). Its homogeneous-coordinate vector is \(\begin{bmatrix}-2\\1\\1\end{bmatrix}\), and the translation matrix is

$$ \mathbf{T}= \begin{bmatrix} 1&0&3\\ 0&1&-4\\ 0&0&1 \end{bmatrix}. $$

Multiply row by row:

$$ \mathbf{T} \begin{bmatrix}-2\\1\\1\end{bmatrix} = \begin{bmatrix} 1(-2)+0(1)+3(1)\\ 0(-2)+1(1)-4(1)\\ 0(-2)+0(1)+1(1) \end{bmatrix} = \begin{bmatrix}1\\-3\\1\end{bmatrix}. $$

The last coordinate is \(1\), so the transformed point is \((1,-3)\). Check: adding the translation vector directly gives \((-2+3,1-4)=(1,-3)\), agreeing with the matrix product.

Rotations, Scalings, and Shears

A transformation that is already given by a \(2\times2\) matrix \(\mathbf{A}\) can be placed in the upper-left corner of a \(3\times3\) homogeneous-coordinate matrix. The final row \(\begin{bmatrix}0&0&1\end{bmatrix}\) keeps the last coordinate equal to \(1\). For a counterclockwise rotation about the origin by angle \(\theta\), the \(2\times2\) matrix is \(\begin{bmatrix}\cos\theta&-\sin\theta\\\sin\theta&\cos\theta\end{bmatrix}\).

Definition: The homogeneous-coordinate matrix for a counterclockwise rotation through angle \(\theta\) about the origin is \(\begin{bmatrix}\cos\theta&-\sin\theta&0\\\sin\theta&\cos\theta&0\\0&0&1\end{bmatrix}\). The angle is measured from the positive \(x\)-axis, and the rotation does not include a translation.

Worked Example: A Quarter-Turn

Rotate \((2,1)\) counterclockwise by \(90^\circ\). Since \(\cos 90^\circ=0\) and \(\sin 90^\circ=1\), the matrix is

$$ \mathbf{R}= \begin{bmatrix} 0&-1&0\\ 1&0&0\\ 0&0&1 \end{bmatrix}. $$

Applying it to the point column gives

$$ \mathbf{R} \begin{bmatrix}2\\1\\1\end{bmatrix} = \begin{bmatrix} 0(2)-1(1)+0(1)\\ 1(2)+0(1)+0(1)\\ 1 \end{bmatrix} = \begin{bmatrix}-1\\2\\1\end{bmatrix}. $$

Thus the rotated point is \((-1,2)\). Check: the two-coordinate rotation sends \((x,y)\) to \((-y,x)\) for a \(90^\circ\) counterclockwise turn; here that gives \((-1,2)\), as the homogeneous matrix does.

A scaling changes distances from the origin along the coordinate directions. Horizontal and vertical scaling factors need not be equal. A factor of \(0\) collapses that coordinate to zero; a negative factor also reflects that coordinate across the origin.

Definition: Scaling by factors \(s_x\) horizontally and \(s_y\) vertically has homogeneous-coordinate matrix \(\begin{bmatrix}s_x&0&0\\0&s_y&0\\0&0&1\end{bmatrix}\). It sends \((x,y)\) to \((s_xx,s_yy)\).

Worked Example: Unequal Horizontal and Vertical Scaling

Scale the point \((-1,2)\) by \(s_x=2\) and \(s_y=3\). The matrix and point column are

$$ \mathbf{S}= \begin{bmatrix} 2&0&0\\ 0&3&0\\ 0&0&1 \end{bmatrix}, \qquad \mathbf{S} \begin{bmatrix}-1\\2\\1\end{bmatrix} = \begin{bmatrix} 2(-1)+0(2)+0(1)\\ 0(-1)+3(2)+0(1)\\ 1 \end{bmatrix} = \begin{bmatrix}-2\\6\\1\end{bmatrix}. $$

The image is \((-2,6)\). Check: the coordinate rules give \(x'=2(-1)=-2\) and \(y'=3(2)=6\), matching the product.

A shear changes one coordinate by an amount proportional to the other, while leaving the other coordinate unchanged. The name of the shear must be read from its coordinate rule: a horizontal shear changes \(x\), whereas a vertical shear changes \(y\).

Definition: A horizontal shear with parameter \(k\in\mathbb{R}\) sends \((x,y)\) to \((x+ky,y)\) and has homogeneous-coordinate matrix \(\begin{bmatrix}1&k&0\\0&1&0\\0&0&1\end{bmatrix}\). A vertical shear with parameter \(k\) sends \((x,y)\) to \((x,y+kx)\) and has matrix \(\begin{bmatrix}1&0&0\\k&1&0\\0&0&1\end{bmatrix}\).

Worked Example: A Horizontal Shear

Apply a horizontal shear with parameter \(k=2\) to \((-1,3)\). The matrix product is

$$ \begin{bmatrix} 1&2&0\\ 0&1&0\\ 0&0&1 \end{bmatrix} \begin{bmatrix}-1\\3\\1\end{bmatrix} = \begin{bmatrix} 1(-1)+2(3)+0(1)\\ 0(-1)+1(3)+0(1)\\ 1 \end{bmatrix} = \begin{bmatrix}5\\3\\1\end{bmatrix}. $$

The image is \((5,3)\). Check: the horizontal shear rule gives \(x'=x+2y=-1+2(3)=5\), while \(y'=y=3\). Both coordinates agree with the matrix product.

Why the Homogeneous Matrix Form Works

The common structure can be stated for any affine rule on the plane. Here an affine map means a function \(T:\mathbb{R}^2\to\mathbb{R}^2\) of the form \(T(\mathbf{x})=\mathbf{A}\mathbf{x}+\mathbf{t}\), where \(\mathbf{A}\in\mathbb{R}^{2\times2}\), \(\mathbf{t}\in\mathbb{R}^2\), and \(\mathbf{x}=\begin{bmatrix}x\\y\end{bmatrix}\). This description includes the translations and the origin-centred linear transformations defined above.

Theorem: If \(T(\mathbf{x})=\mathbf{A}\mathbf{x}+\mathbf{t}\), with \(\mathbf{A}\in\mathbb{R}^{2\times2}\) and \(\mathbf{t}=\begin{bmatrix}a\\b\end{bmatrix}\in\mathbb{R}^2\), then \(\begin{bmatrix}\mathbf{A}&\mathbf{t}\\0&0&1\end{bmatrix}\begin{bmatrix}x\\y\\1\end{bmatrix}=\begin{bmatrix}T(\mathbf{x})\\1\end{bmatrix}\). This is the unique matrix of the displayed block form that represents \(T\) on every point of \(\mathbb{R}^2\).

Proof. Write \(\mathbf{A}=\begin{bmatrix}a_{11}&a_{12}\\a_{21}&a_{22}\end{bmatrix}\). Multiplying the block matrix by the homogeneous-coordinate vector gives \(\begin{bmatrix}a_{11}x+a_{12}y+a\\a_{21}x+a_{22}y+b\\1\end{bmatrix}\). Its first two entries are exactly \(\mathbf{A}\mathbf{x}+\mathbf{t}=T(\mathbf{x})\), and its last entry is \(1\). This proves that the displayed matrix represents \(T\). To prove uniqueness within this block form, suppose another such matrix has upper-left block \(\mathbf{B}\) and last column’s first two entries \(\mathbf{s}\), and represents the same \(T\) for every \(\mathbf{x}\). At \(\mathbf{x}=\begin{bmatrix}0\\0\end{bmatrix}\), equality gives \(\mathbf{s}=\mathbf{t}\). At \(\mathbf{x}=\begin{bmatrix}1\\0\end{bmatrix}\), equality gives \(\mathbf{B}\begin{bmatrix}1\\0\end{bmatrix}+\mathbf{t}=\mathbf{A}\begin{bmatrix}1\\0\end{bmatrix}+\mathbf{t}\), so the first columns of \(\mathbf{B}\) and \(\mathbf{A}\) agree. At \(\mathbf{x}=\begin{bmatrix}0\\1\end{bmatrix}\), the same equality shows their second columns agree. Thus \(\mathbf{B}=\mathbf{A}\), \(\mathbf{s}=\mathbf{t}\), and the matrices are identical. \(\square\)

This result explains the placement of the entries. The upper-left block supplies the linear coordinate changes, the last column supplies constant shifts, and the final row keeps the homogeneous coordinate equal to \(1\). A translation has \(\mathbf{A}=\mathbf{I}_2\); a rotation, scaling, or shear about the origin has \(\mathbf{t}=\mathbf{0}\). These are different choices within the same matrix form.

Common Mistake: Treating Translation as a Two-by-Two Product

A frequent error is to try to translate a point by multiplying only its two-coordinate column by the \(2\times2\) identity matrix. For example, applying \(\mathbf{I}_2\) to \(\begin{bmatrix}2\\-1\end{bmatrix}\) gives \(\begin{bmatrix}2\\-1\end{bmatrix}\), not the translation of \((2,-1)\) by \((3,4)\). The identity matrix leaves the point unchanged; it has no entries that can add \(3\) and \(4\).

The correction is to use the homogeneous-coordinate vector and put the translation in the last column:

$$ \begin{bmatrix} 1&0&3\\ 0&1&4\\ 0&0&1 \end{bmatrix} \begin{bmatrix}2\\-1\\1\end{bmatrix} = \begin{bmatrix}2+3\\-1+4\\1\end{bmatrix} = \begin{bmatrix}5\\3\\1\end{bmatrix}. $$

The result represents \((5,3)\), which also follows by adding the translation vector to the original coordinates. Another error is to put \(a\) and \(b\) in the final row. For the column convention used here, those entries must be in the last column: the matrix product shows exactly where each contribution to the output coordinates comes from.

These matrices are useful because a point remains a column vector throughout the calculation, and each transformation has a concrete \(3\times3\) representation. The final coordinate also gives a quick check: for every translation, rotation, scaling, or shear defined here, an input with final coordinate \(1\) must have output final coordinate \(1\). If it does not, either the matrix or the multiplication has been entered incorrectly.

Check Your Understanding

For each matrix calculation, identify the transformation and interpret the output as a point in \(\mathbb{R}^2\).

  1. Write the homogeneous-coordinate matrix for translation by \((-2,5)\), and apply it to \((1,0)\).
  2. Rotate \((1,-2)\) counterclockwise by \(90^\circ\). Show the matrix product and the resulting point.
  3. Apply horizontal scaling by \(3\) and vertical scaling by \(\tfrac12\) to \((2,-4)\).
  4. Write the matrix for a vertical shear with parameter \(k=-2\), and apply it to \((3,1)\).
  5. In an affine matrix of the form \(\begin{bmatrix}\mathbf{A}&\mathbf{t}\\0&0&1\end{bmatrix}\), explain which part supplies the translation and why the output’s last coordinate is \(1\).

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon