# Finding the appropriate Linear Transformation given input and output points

I'm trying to solve this problem about finding the right Linear Transformation $\phi: \mathbb{R^2} \rightarrow \mathbb{R^2}$ which maps a set of 3 given points $A=(x_A, y_A) \space \space B=(x_B, y_B) \space \space C=(x_C, y_C) \space$ to 3 other given points $A'=(x_{A'}, y_{A'}) \space B'=(x_{B'}, y_{B'}) \space C'=(x_{C'}, y_{C'})$ respectively.

My first idea was to check whether 2 of those vectors were a basis for $\mathbb{R^2}$ and express the other one as a linear combination like this:

$(x',y')=\alpha(x_A,y_A)+\beta(x_B,y_B)+\gamma(x_C,y_C)$

and then I can find $\alpha, \space \beta, \space \gamma$.

I'm not sure how to proceed from here, would there be a better approach?

• What were you planning to do with these scalars once you found them? – amd Jul 2 '18 at 19:35

## 2 Answers

Say you have more than two points, you can also consider for \begin{equation} T = \begin{pmatrix} T_{11} & T_{12}\\ T_{21} & T_{22} \end{pmatrix} \end{equation} the problem \begin{equation} \min_{T} \|XT-X'\|_F^2 \end{equation} with \begin{equation} X = \begin{pmatrix} x_1 & y_1\\ x_2 & y_2\\ x_3 & y_3 \end{pmatrix},\quad X' = \begin{pmatrix} x_1 '& y_1'\\ x_2' & y_2'\\ x_3' & y_3' \end{pmatrix}. \end{equation} This may look too difficult, but we have the closed-form expression for the minimizer (assuming $X$ is of sufficient rank): \begin{equation} T^{\star}=(X^{\top}X)^{-1}X^{\top}X' \end{equation} which is your desired transformation. Note that for more than two points a transformation which does the trick exactly, might simply not exist.

• Interesting, does the transformation not exist if $(X^TX)^{-1}$ does not exist? – Brave Shine Jul 2 '18 at 20:14
• In that case you find $T^{\star}$ indeed, but it might be the case the map $T:\mathbb{R}^2\to \mathbb{R}^2$ you are looking for does not exist. Remember, this is a least-squares approach. – WalterJ Jul 2 '18 at 20:17

A linear transformation $$T:\mathbb {R^2} \to \mathbb {R^2}$$ is determined by a $2\times 2$ matrix $$M = \begin {bmatrix} a &b\\c&d\end {bmatrix}$$

To find such a matrix all you need is two points on the plane with their images.

If $(x_1,y_1)$ and $(x_2, y_2)$ map to $(u_1,v_1)$ and $(u_2, v_2)$ respectively, then we solve the sustem

$$ax_1+by_1 =u_1, cx_1+dy_1 =u_2, ax_2+by_2 =u_2, cx_2+dy_2 =v_2$$

for $a,b,c,d$ and the transformation is simply $$T(x,y) = M\binom {x}{y}$$

• To be precise, you need two linearly independent points and there images to completely determine the map. – amd Jul 2 '18 at 20:52
• Correct. We need to be able to solve the system. – Mohammad Riazi-Kermani Jul 2 '18 at 21:03