Tutorials › Linear Algebra › Changing Coordinate Frames in 2D Graphics

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

Changing Coordinate Frames in 2D Graphics

Build and use frame matrices to convert a point’s coordinates between two planar coordinate systems, then verify the result in world coordinates.

Intermediate 10 min read

What You'll Learn

  • Represent a planar coordinate frame with a homogeneous matrix whose columns record its axes and origin.
  • Convert point coordinates from one frame to another using the correct matrix order.
  • Find a frame matrix inverse and check it by multiplication.
  • Reverse a coordinate conversion and compose conversions through an intermediate frame.
  • Diagnose the common mistake of applying a frame conversion to coordinates in the wrong frame.

One Point, Two Coordinate Descriptions

A point in a drawing can be described using coordinates measured from different origins and along different axes. The point itself does not move when its description changes; only its coordinates do. The main challenge is keeping track of which frame a coordinate column belongs to and applying transformations in the correct order. Homogeneous coordinates make this bookkeeping a matrix calculation.

Work in \(\mathbb{R}^2\). A planar coordinate frame \(A\) consists of an origin \(\mathbf{o}_A\) and two linearly independent axis vectors \(\mathbf{b}_{A,1}\) and \(\mathbf{b}_{A,2}\), all expressed in a common world coordinate system. A point with coordinates \((u,v)\) in frame \(A\) has world position \(\mathbf{o}_A+u\mathbf{b}_{A,1}+v\mathbf{b}_{A,2}\). Independence of the axes ensures that the frame gives unique coordinates to every point in the plane.

Definition: The homogeneous frame matrix for frame \(A\) is $$ \mathbf{F}_A= \begin{bmatrix} |&|&|\\ \mathbf{b}_{A,1}&\mathbf{b}_{A,2}&\mathbf{o}_A\\ |&|&| \end{bmatrix} = \begin{bmatrix} b_{11}&b_{12}&o_1\\ b_{21}&b_{22}&o_2\\ 0&0&1 \end{bmatrix}. $$ If a point has coordinates \(\mathbf{q}_A=(u,v,1)^\top\) in frame \(A\), then its world homogeneous coordinate column is \(\mathbf{x}=\mathbf{F}_A\mathbf{q}_A\). The last coordinate is \(1\) because \(\mathbf{q}_A\) represents a point.

The upper-left \(2\times2\) block records the frame’s axis directions and scales; the third column records its origin. Since the two axes are linearly independent, that block is invertible, and therefore \(\mathbf{F}_A\) is invertible. In particular, knowing a point’s world position determines its coordinates in frame \(A\) by \(\mathbf{q}_A=\mathbf{F}_A^{-1}\mathbf{x}\).

The Conversion Formula and Its Direction

Suppose frames \(A\) and \(B\) are both expressed relative to the same world coordinates. Start with a point’s coordinates in \(A\). Multiplying by \(\mathbf{F}_A\) expresses the point in world coordinates; multiplying by \(\mathbf{F}_B^{-1}\) converts that world description into coordinates in \(B\). Thus the conversion matrix from \(A\)-coordinates to \(B\)-coordinates is \(\mathbf{F}_B^{-1}\mathbf{F}_A\), not \(\mathbf{F}_A^{-1}\mathbf{F}_B\).

Theorem (Coordinate conversion): Let \(A\) and \(B\) be planar coordinate frames with invertible homogeneous frame matrices \(\mathbf{F}_A\) and \(\mathbf{F}_B\). For a point with homogeneous coordinates \(\mathbf{q}_A\) in frame \(A\), its coordinates \(\mathbf{q}_B\) in frame \(B\) are $$ \mathbf{q}_B=\mathbf{F}_B^{-1}\mathbf{F}_A\mathbf{q}_A. $$ The reverse conversion is \(\mathbf{q}_A=\mathbf{F}_A^{-1}\mathbf{F}_B\mathbf{q}_B\).

Proof. Let \(\mathbf{x}\) be the point’s world homogeneous coordinate column. By the definition of a frame matrix, \(\mathbf{x}=\mathbf{F}_A\mathbf{q}_A\) and \(\mathbf{x}=\mathbf{F}_B\mathbf{q}_B\). Equating these expressions gives \(\mathbf{F}_B\mathbf{q}_B=\mathbf{F}_A\mathbf{q}_A\). Since \(\mathbf{F}_B\) is invertible, multiplying on the left by \(\mathbf{F}_B^{-1}\) gives \(\mathbf{q}_B=\mathbf{F}_B^{-1}\mathbf{F}_A\mathbf{q}_A\). For the reverse direction, start from \(\mathbf{F}_A\mathbf{q}_A=\mathbf{F}_B\mathbf{q}_B\) and multiply on the left by \(\mathbf{F}_A^{-1}\), obtaining \(\mathbf{q}_A=\mathbf{F}_A^{-1}\mathbf{F}_B\mathbf{q}_B\). \(\square\)

The order of the factors follows the route the point takes: first from frame \(A\) to the world description, then from the world description to frame \(B\). Matrix products act from right to left. The product \(\mathbf{F}_B^{-1}\mathbf{F}_A\) converts coordinates; neither factor alone does so. The expression also assumes that both frames are described relative to the same world system.

Finding and Checking a Frame Inverse

Worked Example: Inverting a Frame Matrix

Consider a frame \(B\) whose first axis is \((1,1)^\top\), second axis is \((-1,1)^\top\), and origin is \((1,0)^\top\). Its frame matrix is

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

The \(2\times2\) axis block has inverse \(\begin{bmatrix}\frac12&\frac12\\-\frac12&\frac12\end{bmatrix}\). Applying that inverse to the origin gives \((\frac12,-\frac12)^\top\); negating this result gives the translation column of the homogeneous inverse. Therefore

$$ \mathbf{F}_B^{-1}= \begin{bmatrix} \frac12&\frac12&-\frac12\\ -\frac12&\frac12&\frac12\\ 0&0&1 \end{bmatrix}. $$

For example, the first row of \(\mathbf{F}_B\) multiplied by the third column of \(\mathbf{F}_B^{-1}\) gives \(-\frac12-\frac12+1=0\). Checking the whole product gives

$$ \mathbf{F}_B\mathbf{F}_B^{-1} = \begin{bmatrix} \frac12+\frac12&\frac12-\frac12&-\frac12-\frac12+1\\ \frac12-\frac12&\frac12+\frac12&-\frac12+\frac12\\ 0&0&1 \end{bmatrix} = \mathbf{I}_3. $$

Now convert the world point \(\mathbf{x}=(4,3,1)^\top\) into frame \(B\):

$$ \mathbf{q}_B = \mathbf{F}_B^{-1}\mathbf{x} = \begin{bmatrix} \frac12(4)+\frac12(3)-\frac12\\ -\frac12(4)+\frac12(3)+\frac12\\ 1 \end{bmatrix} = \begin{bmatrix}3\\0\\1\end{bmatrix}. $$

Check: Reconstruct the world point with frame \(B\): \(\mathbf{F}_B(3,0,1)^\top=(3+1,3,1)^\top=(4,3,1)^\top\), the original point.

Converting Between Two Nonstandard Frames

Worked Example: From Frame A to Frame B

Let frame \(A\) have origin \((1,2)^\top\) and axes \((1,1)^\top\), \((-1,1)^\top\). Let frame \(B\) have origin \((0,1)^\top\) and axes \((2,0)^\top\), \((1,1)^\top\). Their frame matrices are

$$ \mathbf{F}_A= \begin{bmatrix}1&-1&1\\1&1&2\\0&0&1\end{bmatrix}, \qquad \mathbf{F}_B= \begin{bmatrix}2&1&0\\0&1&1\\0&0&1\end{bmatrix}. $$

The inverse for \(B\) is

$$ \mathbf{F}_B^{-1}= \begin{bmatrix} \frac12&-\frac12&\frac12\\ 0&1&-1\\ 0&0&1 \end{bmatrix}. $$

Indeed, multiplying \(\mathbf{F}_B\mathbf{F}_B^{-1}\) gives first row \((1,0,1-1+0)=(1,0,0)\), second row \((0,1,-1+1)=(0,1,0)\), and bottom row \((0,0,1)\). The conversion matrix is

$$ \mathbf{F}_B^{-1}\mathbf{F}_A = \begin{bmatrix} 0&-1&0\\ 1&1&1\\ 0&0&1 \end{bmatrix}. $$

For a point with \(\mathbf{q}_A=(2,1,1)^\top\), multiply to obtain \(\mathbf{q}_B=(-1,4,1)^\top\). Check in world coordinates: \(\mathbf{F}_A\mathbf{q}_A=(2,5,1)^\top\), while \(\mathbf{F}_B\mathbf{q}_B=(2(-1)+4,\;4+1,\;1)^\top=(2,5,1)^\top\). Both coordinate descriptions identify the same point.

A conversion matrix has a useful structural feature: its bottom row is \((0,0,1)\). It takes a point column with last entry \(1\) to another point column with last entry \(1\). Its top two entries may change through a mixture of rotation, scaling, shear, and translation, because the frames may differ in their origins and axes.

Reversing and Composing Conversions

The reverse of a conversion from \(A\) to \(B\) must undo that conversion. The order of the inverse factors reverses as well. More generally, conversion through an intermediate frame gives the same result as converting directly, provided the intermediate coordinates are represented in the frame named by each factor.

Theorem (Composition of frame conversions): For three planar frames \(A,B,C\), define \(\mathbf{C}_{B\leftarrow A}=\mathbf{F}_B^{-1}\mathbf{F}_A\). Then $$ \mathbf{C}_{A\leftarrow B}=\left(\mathbf{C}_{B\leftarrow A}\right)^{-1}, \qquad \mathbf{C}_{C\leftarrow B}\mathbf{C}_{B\leftarrow A} =\mathbf{C}_{C\leftarrow A}. $$

Proof. Since each frame matrix is invertible, \(\left(\mathbf{F}_B^{-1}\mathbf{F}_A\right)^{-1}=\mathbf{F}_A^{-1}\mathbf{F}_B\), which is exactly \(\mathbf{C}_{A\leftarrow B}\). For composition, substitute the definitions and use associativity of matrix multiplication: \(\mathbf{C}_{C\leftarrow B}\mathbf{C}_{B\leftarrow A}=(\mathbf{F}_C^{-1}\mathbf{F}_B)(\mathbf{F}_B^{-1}\mathbf{F}_A)=\mathbf{F}_C^{-1}(\mathbf{F}_B\mathbf{F}_B^{-1})\mathbf{F}_A=\mathbf{F}_C^{-1}\mathbf{F}_A=\mathbf{C}_{C\leftarrow A}\). The cancellation is valid because \(\mathbf{F}_B\) is invertible. \(\square\)

Worked Example: A Rotated and Shifted Frame

Take frame \(A\) to be the world frame, so \(\mathbf{F}_A=\mathbf{I}_3\). Let frame \(B\) have origin \((2,1)^\top\), with axes \((0,1)^\top\) and \((-1,0)^\top\). Then

$$ \mathbf{F}_B= \begin{bmatrix}0&-1&2\\1&0&1\\0&0&1\end{bmatrix}, \qquad \mathbf{F}_B^{-1}= \begin{bmatrix}0&1&-1\\-1&0&2\\0&0&1\end{bmatrix}. $$

For a world point \(\mathbf{q}_A=(5,4,1)^\top\), the coordinates in \(B\) are \(\mathbf{q}_B=\mathbf{F}_B^{-1}\mathbf{q}_A=(3,-3,1)^\top\). Reconstructing gives \(\mathbf{F}_B\mathbf{q}_B=(3,-5+2+? ,1)^\top\) only if the row calculation is done incorrectly; compute each row directly: the first is \(0(3)-1(-3)+2=5\), and the second is \(1(3)+0(-3)+1=4\). Thus \(\mathbf{F}_B\mathbf{q}_B=(5,4,1)^\top\), as required.

For clarity, the inverse’s second coordinate is \(-5+2=-3\), and its first coordinate is \(4-1=3\). These values also follow geometrically: relative to the origin \((2,1)\), the point is displaced by \((3,3)\); the frame’s first axis accounts for the vertical displacement, while the second axis points left.

Common Mistake: Applying the Conversion in the Wrong Direction

In the nonstandard-frame example, the correct conversion from \(A\) to \(B\) is \(\mathbf{F}_B^{-1}\mathbf{F}_A\). A tempting but incorrect calculation is to apply \(\mathbf{F}_B^{-1}\) directly to \(\mathbf{q}_A=(2,1,1)^\top\), as if those entries were world coordinates. This produces \(\mathbf{F}_B^{-1}\mathbf{q}_A=(1,0,1)^\top\). But \((2,1,1)^\top\) was specified in frame \(A\), not in the world frame, so that multiplication uses the wrong input description.

The error is visible by reconstructing the supposed answer in frame \(B\): \(\mathbf{F}_B(1,0,1)^\top=(2,1,1)^\top\), which is not the original point’s world coordinate \((2,5,1)^\top\). The correct route is to compute \(\mathbf{F}_A\mathbf{q}_A=(2,5,1)^\top\), then apply \(\mathbf{F}_B^{-1}\), giving \((-1,4,1)^\top\). As a practical check, convert the result back to world coordinates; it must reproduce the same point.

Keep the labels attached to the matrices: \(\mathbf{F}_A\) maps \(A\)-coordinates to world coordinates, and \(\mathbf{F}_B^{-1}\) maps world coordinates to \(B\)-coordinates. The subscripted conversion \(\mathbf{C}_{B\leftarrow A}\) is a reminder that the input is in \(A\) and the output is in \(B\). This distinction matters in graphics pipelines, where a point’s numerical column may look identical even when its coordinate frame has changed.

Check Your Understanding

For each question, label the frame of every coordinate column and verify numerical conversions by reconstructing the world point.

  1. A frame has origin \((1,2)^\top\) and axes \((1,0)^\top\), \((0,2)^\top\). Write its homogeneous frame matrix and find the world coordinate of \((3,-1,1)^\top\) in that frame.
  2. If \(\mathbf{q}_A\) is a point’s coordinate column in frame \(A\), write the formula for its coordinates in frame \(B\). Explain why the factors occur in that order.
  3. For \(\mathbf{F}_B=\begin{bmatrix}1&0&2\\0&1&-1\\0&0&1\end{bmatrix}\), find \(\mathbf{F}_B^{-1}\) and check the product.
  4. Show from the conversion formulas that converting from \(A\) to \(B\) and then back to \(A\) recovers the original coordinate column.
  5. Explain what is wrong with applying \(\mathbf{F}_B^{-1}\) directly to a coordinate column known only to be expressed in frame \(A\).

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