M301 Linear Algebra · Week 6

Two Applications of Matrix Algebra

The Leontief input-output model (Section 2.6) · Applications to computer graphics (Section 2.7)

By the end of this week you will be able to:

  • build the consumption matrix of an economy from a description of its sectors, and compute intermediate demand;
  • set up and solve the Leontief production equation \(\mathbf x=C\mathbf x+\mathbf d\), with row reduction or with \((I-C)^{-1}\);
  • explain the meaning of the entries of \((I-C)^{-1}\) and of the series \(I+C+C^2+\cdots\);
  • transform a figure given by a data matrix, and use homogeneous coordinates to write translations, rotations, reflections and scalings as \(3\times3\) matrices;
  • write the matrix of a composite transformation in the right order, including rotation about a point that is not the origin;
  • use \(4\times4\) matrices for transformations of \(\mathbb R^3\), and compute a perspective projection.
This week
  • This note is covered in one lecture. Both sections are applications of the matrix algebra of Week 5.
  • Wednesday: review session for Midterm 1. Friday: Midterm 1.
  • There is no homework this week.
  • Exam scope: Sections 2.6 and 2.7 are not on Midterm 1. They are Midterm 2 material. Expect questions on the Leontief model and on homogeneous coordinates in the second midterm.

Part 1: The Leontief Input-Output Model

An economy with several sectors is described by one matrix. The question "how much must each sector produce?" becomes a matrix equation.

Facts used today
  • For a matrix \(C=[\,\mathbf c_1\ \cdots\ \mathbf c_n\,]\) and a vector \(\mathbf x\): \(C\mathbf x=x_1\mathbf c_1+\cdots+x_n\mathbf c_n\).
  • \(I\mathbf x=\mathbf x\), and \(A\mathbf x-B\mathbf x=(A-B)\mathbf x\).
  • If \(A\) is invertible, \(A\mathbf x=\mathbf b\) has the unique solution \(\mathbf x=A^{-1}\mathbf b\). For \(A=\begin{bmatrix}a&b\\c&d\end{bmatrix}\) with \(ad-bc\neq0\): \(A^{-1}=\dfrac{1}{ad-bc}\begin{bmatrix}d&-b\\-c&a\end{bmatrix}\).

1.1 Sectors, production and demand

Suppose a nation's economy is divided into \(n\) sectors that produce goods or services. Let \(\mathbf x\) in \(\mathbb R^n\) be the production vector: it lists the output of each sector for one year. Another part of the economy, the open sector, does not produce anything; it only consumes. Let \(\mathbf d\) be the final demand vector: it lists the values demanded from each sector by the open sector (consumers, government, exports, and so on).

The producing sectors also demand goods from each other, because they need inputs to produce. This is called intermediate demand. Leontief asked: is there a production level \(\mathbf x\) such that the amount produced exactly balances the total demand?

\[\{\text{amount produced } \mathbf x\}=\{\text{intermediate demand}\}+\{\text{final demand } \mathbf d\}\]
Definition: unit consumption vector, consumption matrix

The basic assumption of the model is that for each sector \(j\) there is a unit consumption vector \(\mathbf c_j\) in \(\mathbb R^n\) that lists the inputs needed from each sector to produce one unit of output of sector \(j\). All units are measured in millions of dollars, and prices are held constant.

The \(n\times n\) matrix \(C=[\,\mathbf c_1\ \mathbf c_2\ \cdots\ \mathbf c_n\,]\) is the consumption matrix of the economy. Its entry \(c_{ij}\) is the amount of output of sector \(i\) consumed per unit of output of sector \(j\).

As an example, consider an economy with three sectors: manufacturing, agriculture and services. The table lists the inputs consumed per unit of output. Read it column by column: each column is one unit consumption vector.

Inputs consumed per unit of output
Purchased fromManufacturingAgricultureServices
Manufacturing.50.40.20
Agriculture.20.30.10
Services.10.10.30
\(\mathbf c_1\)\(\mathbf c_2\)\(\mathbf c_3\)
Manufacturing Agriculture Services intermediate demand Cx (sectors buy from sectors) Open sector (final demand) final demand d final demand d
Figure 1. The flow of goods in a three-sector economy. Each producing sector buys inputs from the sectors (including itself); the open sector only buys.

Producing one unit of manufacturing output consumes the amounts in \(\mathbf c_1\), so producing 100 units consumes \(100\,\mathbf c_1=(50,20,10)\): 50 units from other companies in the manufacturing sector, 20 from agriculture, 10 from services.

If manufacturing produces \(x_1\) units, agriculture \(x_2\) units and services \(x_3\) units, the intermediate demands they create are \(x_1\mathbf c_1\), \(x_2\mathbf c_2\) and \(x_3\mathbf c_3\). The total intermediate demand is their sum, and a sum of this form is a matrix-vector product:

\[\{\text{intermediate demand}\}=x_1\mathbf c_1+x_2\mathbf c_2+x_3\mathbf c_3=C\mathbf x.\]

1.2 The production equation

Putting the two pieces together, the balance condition "produced = intermediate demand + final demand" becomes an equation for \(\mathbf x\).

The Leontief input-output model (production equation) \[\mathbf x=C\mathbf x+\mathbf d\]

Since \(\mathbf x=I\mathbf x\), the equation can be written as \(I\mathbf x-C\mathbf x=\mathbf d\), that is,

\[(I-C)\mathbf x=\mathbf d.\]
Example 1 (two sectors, solved with an inverse)

An economy has two sectors with consumption matrix and final demand

\[C=\begin{bmatrix}.1&.6\\.5&.2\end{bmatrix},\qquad \mathbf d=\begin{bmatrix}18\\11\end{bmatrix}.\]

Find the production level \(\mathbf x\) that satisfies this demand.

Solution

The coefficient matrix of the production equation is

\[I-C=\begin{bmatrix}1&0\\0&1\end{bmatrix}-\begin{bmatrix}.1&.6\\.5&.2\end{bmatrix}=\begin{bmatrix}.9&-.6\\-.5&.8\end{bmatrix}.\]

Its determinant is \((.9)(.8)-(-.6)(-.5)=.72-.30=.42\neq0\), so \(I-C\) is invertible and by the \(2\times2\) formula

\[(I-C)^{-1}=\frac{1}{.42}\begin{bmatrix}.8&.6\\.5&.9\end{bmatrix}.\]

Then

\[\mathbf x=(I-C)^{-1}\mathbf d=\frac{1}{.42}\begin{bmatrix}.8(18)+.6(11)\\.5(18)+.9(11)\end{bmatrix}=\frac{1}{.42}\begin{bmatrix}14.4+6.6\\9+9.9\end{bmatrix}=\frac{1}{.42}\begin{bmatrix}21\\18.9\end{bmatrix}=\begin{bmatrix}50\\45\end{bmatrix}.\]

Sector 1 must produce 50 units and sector 2 must produce 45 units.

Check. \(C\mathbf x+\mathbf d=\begin{bmatrix}.1(50)+.6(45)\\.5(50)+.2(45)\end{bmatrix}+\begin{bmatrix}18\\11\end{bmatrix}=\begin{bmatrix}32+18\\34+11\end{bmatrix}=\begin{bmatrix}50\\45\end{bmatrix}=\mathbf x\). The intermediate demand is \((32,34)\) and the final demand is \((18,11)\); together they use up exactly what is produced.

Example 2 (three sectors described in words, solved by row reduction)

An economy is divided into three sectors: manufacturing, agriculture and services. For each unit of output, manufacturing requires .10 unit from other companies in that sector, .30 unit from agriculture, and .30 unit from services. For each unit of output, agriculture uses .20 unit of its own output, .60 unit from manufacturing, and .10 unit from services. For each unit of output, the services sector consumes .10 unit from services, .60 unit from manufacturing, but no agricultural products.

(a) Construct the consumption matrix \(C\).
(b) Determine the production levels needed to satisfy a final demand of 18 units for manufacturing, with no final demand for the other sectors. Do not compute an inverse.

Solution

(a) Order the sectors as manufacturing, agriculture, services. Each sentence describes one column: what that sector consumes from each of the three sectors (row order: manufacturing, agriculture, services). \[\mathbf c_1=\begin{bmatrix}.10\\.30\\.30\end{bmatrix}\ (\text{manufacturing}),\quad \mathbf c_2=\begin{bmatrix}.60\\.20\\.10\end{bmatrix}\ (\text{agriculture}),\quad \mathbf c_3=\begin{bmatrix}.60\\0\\.10\end{bmatrix}\ (\text{services}),\] \[C=\begin{bmatrix}.10&.60&.60\\.30&.20&0\\.30&.10&.10\end{bmatrix}.\] Note the order: "agriculture uses .60 unit from manufacturing" goes to row 1 (from manufacturing), column 2 (used by agriculture).
(b) The final demand is \(\mathbf d=(18,0,0)\). The production equation \((I-C)\mathbf x=\mathbf d\) has augmented matrix \[\left[\begin{array}{ccc|c}.9&-.6&-.6&18\\-.3&.8&0&0\\-.3&-.1&.9&0\end{array}\right].\] Multiply every row by 10 to remove the decimals (this scales each equation and does not change the solution): \[\left[\begin{array}{ccc|c}9&-6&-6&180\\-3&8&0&0\\-3&-1&9&0\end{array}\right].\] Interchange \(R_1\leftrightarrow R_2\) and then multiply the new \(R_1\) by \(-1\), so that the pivot is a small positive number: \[\left[\begin{array}{ccc|c}3&-8&0&0\\9&-6&-6&180\\-3&-1&9&0\end{array}\right].\] \(R_2\to R_2-3R_1\) and \(R_3\to R_3+R_1\) clear the first column; then divide \(R_2\) by 6 and \(R_3\) by \(-9\): \[\left[\begin{array}{ccc|c}3&-8&0&0\\0&18&-6&180\\0&-9&9&0\end{array}\right] \sim\left[\begin{array}{ccc|c}3&-8&0&0\\0&3&-1&30\\0&1&-1&0\end{array}\right]\] Interchange \(R_2\leftrightarrow R_3\), then \(R_3\to R_3-3R_2\) and divide \(R_3\) by 2: \[\left[\begin{array}{ccc|c}3&-8&0&0\\0&1&-1&0\\0&3&-1&30\end{array}\right] \sim\left[\begin{array}{ccc|c}3&-8&0&0\\0&1&-1&0\\0&0&2&30\end{array}\right]\] \[\sim\left[\begin{array}{ccc|c}3&-8&0&0\\0&1&-1&0\\0&0&1&15\end{array}\right].\] Back substitution: \(x_3=15\); \(x_2-x_3=0\) gives \(x_2=15\); \(3x_1-8x_2=0\) gives \(x_1=40\). So \[\mathbf x=\begin{bmatrix}40\\15\\15\end{bmatrix}.\] To deliver only 18 units of manufacturing output to the open sector, manufacturing must produce 40 units, and agriculture and services must each produce 15 units. The rest is consumed inside the economy.

Check. \(C\mathbf x=\begin{bmatrix}.1(40)+.6(15)+.6(15)\\.3(40)+.2(15)+0\\.3(40)+.1(15)+.1(15)\end{bmatrix}=\begin{bmatrix}22\\15\\15\end{bmatrix}\), and \(C\mathbf x+\mathbf d=(22+18,\ 15,\ 15)=(40,15,15)=\mathbf x\).

Exercise 1.A (production level with an inverse)

Self-check only. These exercises are not graded. Entries may be typed as integers, decimals (1.5 or 1,5) or simple fractions (3/2). Your answers are checked by substitution, not by comparison with one stored answer.

Consider the production model \(\mathbf x=C\mathbf x+\mathbf d\) for an economy with two sectors, where

\[C=\begin{bmatrix}.0&.5\\.6&.2\end{bmatrix},\qquad \mathbf d=\begin{bmatrix}50\\30\end{bmatrix}.\]
(a) Write the matrix \((I-C)^{-1}\).
\((I-C)^{-1}=\)
(b) Use it to find the production level that satisfies the final demand.
\(\mathbf x=\)
(a) \(I-C=\begin{bmatrix}1&-.5\\-.6&.8\end{bmatrix}\), \(\det(I-C)=(1)(.8)-(-.5)(-.6)=.8-.3=.5\), so \[(I-C)^{-1}=\frac{1}{.5}\begin{bmatrix}.8&.5\\.6&1\end{bmatrix}=\begin{bmatrix}1.6&1\\1.2&2\end{bmatrix}.\]
(b) \(\mathbf x=(I-C)^{-1}\mathbf d=\begin{bmatrix}1.6(50)+1(30)\\1.2(50)+2(30)\end{bmatrix}=\begin{bmatrix}110\\120\end{bmatrix}\). Check: \(C\mathbf x+\mathbf d=(0+60+50,\ 66+24+30)=(110,120)\).

1.3 When does the model have a good solution?

In Examples 1 and 2 the production vector came out with nonnegative entries, as it should for an economy. The next theorem says this always happens under a natural condition. The column sum of a matrix is the sum of the entries in one column. A column sum of the consumption matrix is less than 1 when a sector needs less than one unit's worth of inputs to produce one unit of output, which is the normal situation.

Theorem 11

Let \(C\) be the consumption matrix for an economy, and let \(\mathbf d\) be the final demand. If \(C\) and \(\mathbf d\) have nonnegative entries and if each column sum of \(C\) is less than 1, then \((I-C)^{-1}\) exists and the production vector

\[\mathbf x=(I-C)^{-1}\mathbf d\]

has nonnegative entries and is the unique solution of \(\mathbf x=C\mathbf x+\mathbf d\).

In Example 1 the column sums of \(C\) are \(.6\) and \(.8\); in Example 2 they are \(.7\), \(.9\) and \(.7\). In both cases the theorem applies.

A formula for \((I-C)^{-1}\)

The following argument suggests why the theorem is true and gives a second way to compute \((I-C)^{-1}\). Imagine that the demand \(\mathbf d\) is presented to the industries at the beginning of the year, and they set their production at \(\mathbf x=\mathbf d\). To produce \(\mathbf d\) they need inputs, which creates an intermediate demand of \(C\mathbf d\). To meet this additional demand they need further inputs \(C(C\mathbf d)=C^2\mathbf d\), which creates a third round of demand \(C^3\mathbf d\), and so on.

Demand that must be metInputs needed to meet this demand
Final demand \(\mathbf d\)\(C\mathbf d\)
1st round: \(C\mathbf d\)\(C(C\mathbf d)=C^2\mathbf d\)
2nd round: \(C^2\mathbf d\)\(C(C^2\mathbf d)=C^3\mathbf d\)
3rd round: \(C^3\mathbf d\)\(C(C^3\mathbf d)=C^4\mathbf d\)
\(\vdots\)\(\vdots\)

The production level that meets all of this demand is

\[\mathbf x=\mathbf d+C\mathbf d+C^2\mathbf d+C^3\mathbf d+\cdots=(I+C+C^2+C^3+\cdots)\,\mathbf d. \tag{6}\]

To make sense of the infinite sum, multiply out the product below (most terms cancel in pairs):

\[(I-C)(I+C+C^2+\cdots+C^m)=I-C^{m+1}. \tag{7}\]

It can be shown that if the column sums of \(C\) are all strictly less than 1, then \(I-C\) is invertible and \(C^m\) approaches the zero matrix as \(m\) grows. (Compare: if \(0 \[(I-C)^{-1}\approx I+C+C^2+C^3+\cdots+C^m\qquad\text{when the column sums of }C\text{ are less than }1. \tag{8}\]

The right side can be made as close to \((I-C)^{-1}\) as desired by taking \(m\) large enough. In real input-output models the powers \(C^m\) become small quickly, so (8) is a practical way to compute \((I-C)^{-1}\), and (6) is a practical way to solve \((I-C)\mathbf x=\mathbf d\). Since all entries in \(C\) and \(\mathbf d\) are nonnegative, (6) also shows why \(\mathbf x\) has nonnegative entries.

1.4 The economic meaning of the entries of \((I-C)^{-1}\)

The entries of \((I-C)^{-1}\) predict how the production must change when the final demand changes. Suppose \(\mathbf x\) satisfies the demand \(\mathbf d\) and \(\Delta\mathbf x\) satisfies a different demand \(\Delta\mathbf d\):

\[(I-C)\mathbf x=\mathbf d,\qquad (I-C)\,\Delta\mathbf x=\Delta\mathbf d.\]

Adding the two equations gives \((I-C)(\mathbf x+\Delta\mathbf x)=\mathbf d+\Delta\mathbf d\). So if the final demand changes from \(\mathbf d\) to \(\mathbf d+\Delta\mathbf d\), the new production level is \(\mathbf x+\Delta\mathbf x\), where \(\Delta\mathbf x=(I-C)^{-1}\Delta\mathbf d\).

Now take \(\Delta\mathbf d=\mathbf e_j\), an increase of 1 unit in the final demand for sector \(j\) only. Then \(\Delta\mathbf x=(I-C)^{-1}\mathbf e_j\), which is column \(j\) of \((I-C)^{-1}\).

Exercise 1.B (reading the inverse)

Self-check only. Your vectors are checked by substitution into the production equation.

Let \(C\) and \(\mathbf d\) be as in Exercise 1.A: \(C=\begin{bmatrix}0&.5\\.6&.2\end{bmatrix}\), \(\mathbf d=\begin{bmatrix}50\\30\end{bmatrix}\), \((I-C)^{-1}=\begin{bmatrix}1.6&1\\1.2&2\end{bmatrix}\).

(a) Determine the production level necessary to satisfy a final demand for 1 unit of output from sector 1 (and nothing from sector 2).
\(\mathbf x=\)
(b) Determine the production level necessary to satisfy a final demand of \(\begin{bmatrix}51\\30\end{bmatrix}\).
\(\mathbf x=\)
(c) The answer to (b) is the answer of Exercise 1.A plus the answer to (a). Why?
(a) \(\mathbf x=(I-C)^{-1}\mathbf e_1=\) first column of \((I-C)^{-1}\) \(=\begin{bmatrix}1.6\\1.2\end{bmatrix}\). To deliver one extra unit of sector 1 output, sector 1 must produce 1.6 units and sector 2 must produce 1.2 units.
(b) \(\mathbf x=(I-C)^{-1}\begin{bmatrix}51\\30\end{bmatrix}=\begin{bmatrix}1.6(51)+30\\1.2(51)+60\end{bmatrix}=\begin{bmatrix}111.6\\121.2\end{bmatrix}\).
(c) \(\begin{bmatrix}51\\30\end{bmatrix}=\begin{bmatrix}50\\30\end{bmatrix}+\begin{bmatrix}1\\0\end{bmatrix}\), and multiplication by \((I-C)^{-1}\) is linear: \((I-C)^{-1}(\mathbf d+\mathbf e_1)=(I-C)^{-1}\mathbf d+(I-C)^{-1}\mathbf e_1\). So \((111.6,121.2)=(110,120)+(1.6,1.2)\).

Part 2: Applications to Computer Graphics

A picture on a screen is a list of points. Moving the picture is matrix multiplication, once we choose the right coordinates.

Facts used today
  • The columns of a product \(AD=[\,A\mathbf d_1\ \cdots\ A\mathbf d_k\,]\) are \(A\) times the columns of \(D\).
  • Matrix multiplication is composition: applying \(B\) first and then \(A\) is multiplication by \(AB\). In general \(AB\neq BA\).
  • Standard matrices of some linear transformations of \(\mathbb R^2\): rotation through angle \(\varphi\) about the origin \(\begin{bmatrix}\cos\varphi&-\sin\varphi\\ \sin\varphi&\cos\varphi\end{bmatrix}\); reflection through the \(x\)-axis \(\begin{bmatrix}1&0\\0&-1\end{bmatrix}\); reflection through the \(y\)-axis \(\begin{bmatrix}-1&0\\0&1\end{bmatrix}\); scaling \(x\) by \(s\) and \(y\) by \(t\): \(\begin{bmatrix}s&0\\0&t\end{bmatrix}\).
  • \(\cos 30^\circ=\sin 60^\circ=\sqrt3/2\), \(\ \sin30^\circ=\cos60^\circ=1/2\), \(\ \cos45^\circ=\sin45^\circ=\sqrt2/2\), \(\ \cos90^\circ=0\), \(\ \sin90^\circ=1\).

2.1 Points, data matrices and transformations

A graphical image on a screen (for example a wire-frame model of an airplane, or a letter) consists of a number of points, the lines that connect them, and information about how to fill the regions between the lines. Curved lines are usually approximated by short straight segments, so a figure is defined mathematically by a list of points.

Definition: data matrix

The data matrix \(D\) of a figure in \(\mathbb R^2\) is the \(2\times k\) matrix whose columns are the coordinates of the \(k\) vertices of the figure. (Which vertices are joined by lines is recorded separately.)

12345678
Figure 2. The regular letter N of Example 1, with its eight vertices numbered.

Graphical objects are described by straight-line segments because the standard transformations of computer graphics map line segments onto line segments (a linear transformation maps the segment from \(\mathbf u\) to \(\mathbf v\) onto the segment from \(A\mathbf u\) to \(A\mathbf v\)). So once the vertices have been transformed, their images can be joined by the same lines to produce the complete image of the object.

Example 1 (the letter N: data matrix, shear, composite)

The capital letter N in Figure 2 is determined by eight vertices, joined in the order \(1,2,\dots,8,1\). Its data matrix is

\[D=\begin{bmatrix}0&.5&.5&6&6&5.5&5.5&0\\0&0&6.42&0&8&8&1.58&8\end{bmatrix}.\]
(a) Given \(A=\begin{bmatrix}1&.25\\0&1\end{bmatrix}\), describe the effect of the shear transformation \(\mathbf x\mapsto A\mathbf x\) on the letter.
(b) Compute the matrix of the transformation that performs the shear in (a) and then scales all \(x\)-coordinates by a factor of \(.75\).

Solution

(a) The columns of \(AD\) are the images of the vertices. Each column \((x,y)\) of \(D\) is sent to \((x+.25y,\ y)\): the \(y\)-coordinate stays, and the \(x\)-coordinate is increased by a quarter of the \(y\)-coordinate. For example, vertex 3, \((.5,\ 6.42)\), goes to \((.5+.25(6.42),\ 6.42)=(2.105,\ 6.42)\). All eight columns: \[AD=\begin{bmatrix}0&.5&2.105&6&8&7.5&5.895&2\\0&0&6.42&0&8&8&1.58&8\end{bmatrix}.\] The transformed vertices are plotted in the middle panel of Figure 3, joined by the same segments as before. The result is an italic N. It looks a bit too wide; part (b) fixes that.
(b) The matrix that multiplies the \(x\)-coordinate of a point by \(.75\) and leaves \(y\) alone is \(S=\begin{bmatrix}.75&0\\0&1\end{bmatrix}\). The shear is applied first and the scaling second, so the composite transformation is \(\mathbf x\mapsto S(A\mathbf x)=(SA)\mathbf x\), with matrix \[SA=\begin{bmatrix}.75&0\\0&1\end{bmatrix}\begin{bmatrix}1&.25\\0&1\end{bmatrix}=\begin{bmatrix}.75&.1875\\0&1\end{bmatrix}.\] The data matrix of the final letter is \((SA)D\); for example vertex 5, \((6,8)\), goes to \((.75(6)+.1875(8),\ 8)=(6,\ 8)\) and vertex 4, \((6,0)\), goes to \((4.5,\ 0)\). The result is the right panel of Figure 3.
2 4 6 8 2 4 6 8Regular N 2 4 6 8 2 4 6 8Slanted N: AD 2 4 6 8 2 4 6 8Composite: (SA)D
Figure 3. Left: the letter N. Middle: after the shear \(A\) of Example 1(a). Right: after the composite \(SA\) of Example 1(b) (shear, then scale \(x\) by \(.75\)).

2.2 Homogeneous coordinates

Moving a figure by a fixed vector, \((x,y)\mapsto(x+h,y+k)\), is called a translation. A translation is not a linear transformation (it does not send \(\mathbf 0\) to \(\mathbf 0\)), so it cannot be written as \(\mathbf x\mapsto A\mathbf x\) with a \(2\times2\) matrix. The standard way around this problem is to add one coordinate.

Definition: homogeneous coordinates in \(\mathbb R^2\)

Each point \((x,y)\) in \(\mathbb R^2\) is identified with the point \((x,y,1)\) in \(\mathbb R^3\), on the plane one unit above the \(xy\)-plane. We say that \((x,y)\) has homogeneous coordinates \((x,y,1)\). For example, \((0,0)\) has homogeneous coordinates \((0,0,1)\).

Homogeneous coordinates of points are not added or multiplied by scalars, but they can be transformed by multiplication with \(3\times3\) matrices.

A translation \((x,y)\mapsto(x+h,y+k)\) is written in homogeneous coordinates as \((x,y,1)\mapsto(x+h,y+k,1)\). This is a matrix multiplication:

\[\begin{bmatrix}1&0&h\\0&1&k\\0&0&1\end{bmatrix}\begin{bmatrix}x\\y\\1\end{bmatrix}=\begin{bmatrix}x+h\\y+k\\1\end{bmatrix}.\]

The third coordinate is what makes this work: the constants \(h\) and \(k\) enter through the third column, multiplied by the 1. Figure 4 shows a triangle translated by \((4,3)\).

2 4 6 8 2 4 6 (1,1)(3,1)(2,3) (5,4)(7,4)(6,6) + (4, 3)
Figure 4. Translation by \((4,3)\): every vertex moves by the same vector.

Any linear transformation \(\mathbf x\mapsto A\mathbf x\) of \(\mathbb R^2\) is represented in homogeneous coordinates by the partitioned matrix \(\begin{bmatrix}A&\mathbf 0\\ \mathbf 0^T&1\end{bmatrix}\): the \(2\times2\) block \(A\) acts on \((x,y)\) and the third coordinate stays 1. Typical examples are

\[\begin{bmatrix}\cos\varphi&-\sin\varphi&0\\ \sin\varphi&\cos\varphi&0\\0&0&1\end{bmatrix},\qquad \begin{bmatrix}0&1&0\\1&0&0\\0&0&1\end{bmatrix},\qquad \begin{bmatrix}s&0&0\\0&t&0\\0&0&1\end{bmatrix},\]

which are, in order: counterclockwise rotation about the origin through the angle \(\varphi\); reflection through the line \(y=x\); scaling \(x\) by \(s\) and \(y\) by \(t\). In this way every basic 2D transformation is a \(3\times3\) matrix, so any sequence of them is a product of \(3\times3\) matrices.

2.3 Composite transformations

Moving a figure on a screen often requires two or more basic transformations. With homogeneous coordinates the composition corresponds to matrix multiplication, and the matrices are written from right to left: the first transformation applied is the rightmost factor. For instance, "scale by \(.3\), then rotate \(90^\circ\), then translate by \((-.5,2)\)" is the product

\[\begin{bmatrix}1&0&-.5\\0&1&2\\0&0&1\end{bmatrix}\begin{bmatrix}0&-1&0\\1&0&0\\0&0&1\end{bmatrix}\begin{bmatrix}.3&0&0\\0&.3&0\\0&0&1\end{bmatrix}=\begin{bmatrix}0&-.3&-.5\\.3&0&2\\0&0&1\end{bmatrix},\]

with the scaling matrix on the right because it acts first.

Warning: order

The first transformation you apply is the rightmost matrix in the product. "Translate, then rotate" is \(R\,T\), not \(T\,R\), and the two products are different in general: rotating first and then translating moves the figure to a different place.

Example 2 (rotation about a point that is not the origin)

Rotation of a figure about a point \(\mathbf p\) in \(\mathbb R^2\) is done in three steps (Figure 5): translate the figure by \(-\mathbf p\) so that \(\mathbf p\) moves to the origin, rotate about the origin, and translate back by \(\mathbf p\). The same idea works for reflection through a line that does not pass through the origin, or scaling about a point. Construct the \(3\times3\) matrix that rotates points through \(-30^\circ\) about the point \((-2,6)\), using homogeneous coordinates.

Solution

Here \(\mathbf p=(-2,6)\), \(\cos(-30^\circ)=\sqrt3/2\) and \(\sin(-30^\circ)=-1/2\). The three matrices, written right to left in the order they are applied, are

\[\underbrace{\begin{bmatrix}1&0&-2\\0&1&6\\0&0&1\end{bmatrix}}_{\text{translate back by }\mathbf p}\ \underbrace{\begin{bmatrix}\sqrt3/2&1/2&0\\-1/2&\sqrt3/2&0\\0&0&1\end{bmatrix}}_{\text{rotate about the origin}}\ \underbrace{\begin{bmatrix}1&0&2\\0&1&-6\\0&0&1\end{bmatrix}}_{\text{translate by }-\mathbf p}.\]

Multiply the two right factors first (this replaces the third column of the rotation matrix by the rotated vector \(-\mathbf p\)):

\[\begin{bmatrix}\sqrt3/2&1/2&0\\-1/2&\sqrt3/2&0\\0&0&1\end{bmatrix}\begin{bmatrix}1&0&2\\0&1&-6\\0&0&1\end{bmatrix} =\begin{bmatrix}\sqrt3/2&1/2&\sqrt3-3\\-1/2&\sqrt3/2&-1-3\sqrt3\\0&0&1\end{bmatrix}.\]

Then the left factor adds \(\mathbf p\) to the third column:

\[\begin{bmatrix}1&0&-2\\0&1&6\\0&0&1\end{bmatrix}\begin{bmatrix}\sqrt3/2&1/2&\sqrt3-3\\-1/2&\sqrt3/2&-1-3\sqrt3\\0&0&1\end{bmatrix} =\begin{bmatrix}\sqrt3/2&1/2&\sqrt3-5\\-1/2&\sqrt3/2&5-3\sqrt3\\0&0&1\end{bmatrix}.\]

Check: the center \(\mathbf p\) must not move. The matrix sends \((-2,6,1)\) to \(\big(-\sqrt3+3+\sqrt3-5,\ 1+3\sqrt3+5-3\sqrt3,\ 1\big)=(-2,\ 6,\ 1)\).

-4 4 8p(a) original -4 4 80(b) translate by −p -4 4 80(c) rotate −30° -4 4 8p(d) translate back
Figure 5. Rotation through \(-30^\circ\) about \(\mathbf p=(-2,6)\): (a) the original triangle; (b) translated by \(-\mathbf p\); (c) rotated about the origin; (d) translated back by \(\mathbf p\).
Exercise 2.A (composite transformations)

Self-check only. In (a) your matrix is checked by applying it to several points.

(a) Find the \(3\times3\) matrix that produces the following composite 2D transformation, using homogeneous coordinates: translate by \((-3,4)\), and then scale the \(x\)-coordinate by \(.7\) and the \(y\)-coordinate by \(1.3\).
(b) Consider the following geometric 2D transformations: \(D\), a dilation (both coordinates scaled by the same factor \(r\neq1\)); \(R\), a rotation about the origin through an angle that is not a multiple of \(360^\circ\); and \(T\), a translation by a nonzero vector. Which pairs commute? That is, for which pairs is the result the same in both orders, for every \(\mathbf x\)?
\(D\) and \(R\):
\(D\) and \(T\):
\(R\) and \(T\):
(a) Translation first (right factor), scaling second (left factor): \[\begin{bmatrix}.7&0&0\\0&1.3&0\\0&0&1\end{bmatrix}\begin{bmatrix}1&0&-3\\0&1&4\\0&0&1\end{bmatrix}=\begin{bmatrix}.7&0&-2.1\\0&1.3&5.2\\0&0&1\end{bmatrix}.\] A point \((x,y)\) goes to \((.7(x-3),\ 1.3(y+4))=(.7x-2.1,\ 1.3y+5.2)\).
(b) \(D\) and \(R\) commute: \(D(R(\mathbf x))=r\,R\mathbf x\) and \(R(D(\mathbf x))=R(r\mathbf x)=r\,R\mathbf x\), because \(R\) is linear. \(D\) and \(T\) do not commute: \(D(T(\mathbf x))=r(\mathbf x+\mathbf p)=r\mathbf x+r\mathbf p\), but \(T(D(\mathbf x))=r\mathbf x+\mathbf p\), and \(r\mathbf p\neq\mathbf p\). \(R\) and \(T\) do not commute: \(R(T(\mathbf x))=R\mathbf x+R\mathbf p\), but \(T(R(\mathbf x))=R\mathbf x+\mathbf p\), and \(R\mathbf p\neq\mathbf p\) for a nonzero \(\mathbf p\).

2.4 Homogeneous coordinates in \(\mathbb R^3\)

By analogy with the 2D case, \((x,y,z,1)\) are homogeneous coordinates for the point \((x,y,z)\) in \(\mathbb R^3\). Transformations of \(\mathbb R^3\), including translations, are then \(4\times4\) matrices. A linear transformation with \(3\times3\) standard matrix \(A\) becomes \(\begin{bmatrix}A&\mathbf 0\\ \mathbf 0^T&1\end{bmatrix}\), and a translation by \(\mathbf p=(h,k,l)\) has \(\mathbf p\) in the last column. For example, rotation about the \(z\)-axis through the angle \(\varphi\) (which acts on \(x\) and \(y\) like the 2D rotation and leaves \(z\) alone) and translation by \((-6,4,5)\) are

\[\begin{bmatrix}\cos\varphi&-\sin\varphi&0&0\\ \sin\varphi&\cos\varphi&0&0\\0&0&1&0\\0&0&0&1\end{bmatrix},\qquad \begin{bmatrix}1&0&0&-6\\0&1&0&4\\0&0&1&5\\0&0&0&1\end{bmatrix}.\]

For the perspective projection below we also need the general form of the definition.

Definition: homogeneous coordinates in \(\mathbb R^3\)

\((X,Y,Z,H)\) are homogeneous coordinates for the point \((x,y,z)\) if \(H\neq0\) and

\[x=\frac XH,\qquad y=\frac YH,\qquad z=\frac ZH. \tag{1}\]

Each nonzero scalar multiple of \((x,y,z,1)\) gives a set of homogeneous coordinates for \((x,y,z)\). For instance, both \((10,-6,14,2)\) and \((-15,9,-21,-3)\) are homogeneous coordinates for \((5,-3,7)\).

2.5 Perspective projections

A three-dimensional object is shown on a two-dimensional screen by projecting it onto a viewing plane. Let the \(xy\)-plane represent the screen, and imagine the eye of the viewer on the positive \(z\)-axis, at the point \((0,0,d)\). A perspective projection maps each point \((x,y,z)\) onto an image point \((x^*,y^*,0)\) so that the point, its image and the eye position (the center of projection) lie on one line.

x z screen (z = 0) eye (0, 0, d) (x, y, z) (x*, y*, 0) d − z z x x*
Figure 6. The \(xz\)-plane: the line from the eye \((0,0,d)\) through \((x,y,z)\) meets the screen at \((x^*,y^*,0)\). The two shaded triangles are similar. Drawn with \(d=10\) and the point \((4.2,\ 1.2,\ 4)\), whose image is \((7,\ 2,\ 0)\).

In Figure 6 the small triangle (height \(d-z\), base \(x\)) and the large triangle (height \(d\), base \(x^*\)) are similar, so

\[\frac{x^*}{d}=\frac{x}{d-z}\qquad\text{and}\qquad x^*=\frac{dx}{d-z}=\frac{x}{1-z/d}.\]

The same argument in the \(yz\)-plane gives \(y^*=\dfrac{y}{1-z/d}\).

The division by \(1-z/d\) is not a linear operation, but homogeneous coordinates handle it. We want \((x,y,z,1)\) to map to \(\left(\dfrac{x}{1-z/d},\ \dfrac{y}{1-z/d},\ 0,\ 1\right)\). Scaling these coordinates by \(1-z/d\) gives another set of homogeneous coordinates for the same image point: \((x,\ y,\ 0,\ 1-z/d)\). This one is a linear function of \((x,y,z,1)\), so the projection is a matrix:

\[P\begin{bmatrix}x\\y\\z\\1\end{bmatrix}=\begin{bmatrix}1&0&0&0\\0&1&0&0\\0&0&0&0\\0&0&-1/d&1\end{bmatrix}\begin{bmatrix}x\\y\\z\\1\end{bmatrix}=\begin{bmatrix}x\\y\\0\\1-z/d\end{bmatrix}.\]

To project a figure, multiply \(P\) by its data matrix in homogeneous coordinates, then divide the first three entries of each column by the fourth entry (equation (1)) to read off the points on the screen. Points closer to the eye (larger \(z\)) are pushed farther from the center of the screen; this is the perspective effect.

Exercise 2.B (homogeneous coordinates in 3D and a perspective projection)

Self-check only. Your image points in (c) are checked directly from the formula.

(a) What vector in \(\mathbb R^3\) has homogeneous coordinates \(\left(\tfrac14,\ -\tfrac1{12},\ \tfrac18,\ \tfrac1{36}\right)\)?
\((x,y,z)=\)
(b) Are \((1,-2,3,4)\) and \((10,-20,30,40)\) homogeneous coordinates for the same point in \(\mathbb R^3\)?
(c) Let \(S\) be the triangle with vertices \((9,\ 3,\ -5)\), \((12,\ 8,\ 2)\), \((1.8,\ 2.7,\ 1)\). Find the image of \(S\) under the perspective projection with center of projection at \((0,0,10)\). Enter the image points as the columns of a \(2\times3\) matrix (row 1: \(x^*\), row 2: \(y^*\)).
image \(=\)
(a) Divide the first three coordinates by \(H=\tfrac1{36}\), that is, multiply by 36: \((x,y,z)=(9,\ -3,\ 4.5)\).
(b) Yes. \((10,-20,30,40)=10\,(1,-2,3,4)\), and a nonzero scalar multiple gives homogeneous coordinates of the same point. Both represent \((1/4,\ -1/2,\ 3/4)\).
(c) With \(d=10\), the last row of \(P\) is \((0,0,-.1,1)\). Write the vertices as the columns of a data matrix in homogeneous coordinates and multiply: \[PD=\begin{bmatrix}1&0&0&0\\0&1&0&0\\0&0&0&0\\0&0&-.1&1\end{bmatrix}\begin{bmatrix}9&12&1.8\\3&8&2.7\\-5&2&1\\1&1&1\end{bmatrix}\] \[=\begin{bmatrix}9&12&1.8\\3&8&2.7\\0&0&0\\1.5&.8&.9\end{bmatrix}.\] The fourth row is \(1-z/10\) for each vertex. The first vertex has \(z=-5\), behind the screen, so its fourth entry is \(1+.5=1.5>1\) and its image is pulled toward the center. Divide the top entries of each column by the fourth entry: \[(9/1.5,\ 3/1.5)=(6,\ 2),\qquad (12/.8,\ 8/.8)=(15,\ 10),\qquad (1.8/.9,\ 2.7/.9)=(2,\ 3).\] The image is the triangle with vertices \((6,2,0)\), \((15,10,0)\), \((2,3,0)\).