# How to find a transformation matrix, given coordinates of two triangles in $R^2$

I am an undergraduate student, and today I was given two triangles, $T_1$ (green) and $T_2$ (blue) in $R^2$:

I was then asked to find the transformation matrix transforming $T_1$ to $T_2$. What I understand from this is, that I need to find $F$ in the following matrix equation:

$T_2 = F \cdot T_1$.

where

$T_1= \begin{bmatrix}2&6&8\\2&-2&6\end{bmatrix}$

$T_2= \begin{bmatrix}-2&-10&-14\\-2&-4&10\end{bmatrix}$

which are the coordinates of the corners of the triangles.

The above matrix equation however, is inconsistent, so how can I find $F$?

It has to be a linear mapping, not an affine one.

Have tried a lot, any help greatly appreciated!

• Say your plane is $z=1$. What does this do to your matrices? – shade4159 Nov 9 '13 at 1:15
• Well, then I add a row no. 3 to each of the matrices, filled with 1 (ones). Then I get F = T2.T1^-1 = [ [-2, 0 2], [1, 3/2, -7], [0, 0, 1] ]. But how can I generalize this to work in any plane? – Troels Folke Nov 9 '13 at 1:29
• As long as you are in $\Bbb R^2$, which plane you use should be irrelevant. But you might want to try Gauss-Jordan Elimination. – shade4159 Nov 9 '13 at 1:38
• Yes, when z=1, I can use Gauss-Jordan elimination to find the inverse of T1, and multiply that with T2 to get F. But that F will only work for triangles where z=1. If z=0, T1 becomes singular, and I cannot find an inverse of it. – Troels Folke Nov 9 '13 at 1:47
• My mistake, any plane but $z=0$. – shade4159 Nov 9 '13 at 1:49

The vertices of $T_1$ are $(2,2)$, $(6,-2)$, and $(8,6)$. The vertices of $T_2$ are $(-2,-2)$, $(-10,-4)$, and $(-14,10)$. We want a transformation mapping $T_1$ to $T_2$. So the vertices of $T_1$ must map to the vertices of $T_2$. Let's factor out the 2 to save us some trouble. We seek a linear transformation $L:\mathbb{R}^2 \to \mathbb{R}^2$ with $$\{(1,1), (3,-1), (4,3)\} \mapsto \{(-1,-1), (-5,-2), (-7,5)\}$$ The map $L$ is determined by its action on the two linearly independent vectors $(1,1)$ and $(4,3)$. It must map them to two of the vectors in $\{(-1,-1), (-5,-2), (-7,5)\}$. Using this we can easily calculate a matrix.

For example, the matrix mapping $(1,1) \mapsto (-1,-1)$ and $(4,3) \mapsto (-5,-2)$ is $$\begin{pmatrix} -2 & 1 \\ 1 & -2 \end{pmatrix}.$$ This matrix also happens to map $(3,-1)$ to the remaining vector $(-7,5)$ and so we are done. We got lucky this time; if this hadn't mapped to the right vector we could have kept choosing different pairs of vectors until we found the correct map.

• Please specify how you built the matrix – SteakOverflow Mar 27 '17 at 8:21
• This doesn't answer the question as to "how", this just says, "get the matrix that you need and you are done". What about more complex exercises where this isn't as trivial? – Miguel Bartelsman May 9 at 10:56

Organize each of the points of the starting triangle as columns in a matrix $\mathbf{U}$, and each of the points of the resulting triangle as columns in a matrix $\mathbf{V}$. Thus, both $\mathbf{U}$ and $\mathbf{V}$ are $3\times3$ matrices because you have 3 vertices, each vertex having 3 coordinates (I am assuming the triangles are contained in $\mathbb{R}^3$ space).

Now, assume there is a matrix $\mathbf{T}$ such that $\mathbf{T}\mathbf{U}=\mathbf{V}$. All you need to do is to isolate $\mathbf{T}$:

$$\mathbf{T}\mathbf{U}\mathbf{U}^{-1}=\mathbf{V}\mathbf{U}^{-1}\\ \mathbf{T}=\mathbf{V}\mathbf{U}^{-1}$$

Using the vertices of the triangles as columns in $\mathbf{U}$ and $\mathbf{V}$ is just a convenient way of writing the problem in matrix form.

• as they are in the plane, you should use "0 0 1" as the last row for each of T1 and T2 matrices – Girardi Sep 15 '18 at 21:41

Another way to get the answer is to notice that you can map $T_1$ to $T_2$ by reflecting $T_1$ in the origin and then scaling the result by 3 with respect to the diagonal $x=y$. Reflecting in the origin is simply $(x,y)\mapsto (-x,-y)$ and scaling is given by $(x,y)\mapsto(x+(x-y),y-(x-y))$.

Incidentally, the formula for scaling $(x,y)$ by $\gamma$ with respect to a line defined by $ax+by+d=0$ is

$$x\mapsto x+(\gamma-1)\frac{a(ax+by+d)}{(a^2+b^2)}\quad \text{and}\quad y\mapsto y+(\gamma-1)\frac{b(ax+by+d)}{(a^2+b^2)}.$$

If $(x,y)$ is at the distance $r$ from the line, then after it is scaled by $\gamma$ it will be at the distance $\gamma r$ from the line.


We just need a symmetric $3 \times 3$ real matrix $F$ where $F$ satisfy $F{\bf P}_{i} = {\bf P}_{i}'$. $i = 1, 2, 3$. ${\bf P}_{i}$ and ${\bf P}_{i}'$ are the triangle vertices "before" ( one of them ) and "after" ( the other one ) the transformation generated by the matrix $F$. With the vectors $${\bf 1} \equiv \pars{\begin{array}{c}1 \\ 0 \\ 0\end{array}}\,, \qquad {\bf 2} \equiv \pars{\begin{array}{c}0 \\ 1 \\ 0\end{array}}\,, \qquad {\bf 3} \equiv \pars{\begin{array}{c}0 \\ 0 \\ 1\end{array}}$$ The $F$ matrix elements $F_{ij} \equiv {\bf i}^{\sf T}F\,{\bf j}$ become $$\color{#0000ff}{\large F_{ij}} = {\bf i}^{\sf T}F\sum_{\ell = 1, 2, 3}{\bf P}_{\ell}{\bf P}_{\ell}^{\sf T}\,{\bf j} = \color{#0000ff}{\large{\bf i}^{\sf T}\,\pars{\sum_{\ell = 1, 2, 3} {\bf P}_{\ell}'{\bf P}_{\ell}^{\sf T}}\,\,{\bf j}}$$

Notice that this is the ${\large\tt 3D}$ result but the idea can be straightforward 'translated' to ${\large\tt 2D}$.