# Using transformations to get from A to B image

I try to solve this, First, I used scaling: $$Scale(S_x,S_y)=S(\sqrt 5,\sqrt 5)$$

So, I enlarge the bottom of the house and the sides, to the same size of B image.

Later, I used rotation: $$R(\theta)=R(cos^{-1}(2/\sqrt 5))$$ the vertex that was $$[\sqrt 5, 0, 1]$$ moved $$[2, 1, 1]$$ I do that because I thought to translate it to $$[5,3,1]$$

But I stuck with that.

What is the idea of this question?

Thanks.

• Could there be shear in the matrix? – user1118321 Feb 11 '19 at 5:53
• There definitely is a shear involved. Seems like a shear in the X-coordinate. – gallickgunner Feb 11 '19 at 8:54
• Yes, one of the matrices is Shear, but I don't understand when to use it. – Asaf Feb 11 '19 at 10:13
• Try Shearing > Scaling > Rotating > Translatng. As long as the scaling is uniform it doesnt matter if you do shearing or scaling first. Translation wouldn't affect shearing though, not quite sure about rotation. Why don't you try shearing before and after rotation. And post the results. Would be a nice find :) – gallickgunner Feb 11 '19 at 11:25
• You can find the complete transform matrix T in one step minimizing a linear least squares error. – Mauricio Cele Lopez Belon Feb 11 '19 at 12:35

Just use linear algebra.

Since parallel lines have remained parallel (i.e. meaning we can probably assume the w component of homogeneous coordinates is always 1), we can just pick 3 starting points and their destinations, e.g.

(0,0,1)->(3,2,1),  (0,1,1)->(1,3,1), and  (1,0,1)->(5,3,1),


define M to be your (homogeneous) transformation matrix as

$$M =\begin{bmatrix} a & b & c \\ d & e & f \\ 0 & 0 & 1\\ \end{bmatrix}$$ and then we have $$M.\begin{bmatrix} 0 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 1 & 1\\ \end{bmatrix} = \begin{bmatrix} 3 & 1 & 5 \\ 2 & 3 & 3 \\ 1 & 1 & 1\\ \end{bmatrix}$$

You just need to find the inverse of the 'starting point' matrix (which is left as an exercise for the reader ) and rearrange to compute... $$M= \begin{bmatrix} 3 & 1 & 5 \\ 2 & 3 & 3 \\ 1 & 1 & 1\\ \end{bmatrix} .\begin{bmatrix} 0 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 1 & 1\\ \end{bmatrix}^{-1}$$

To be really thorough, you could also then check that all the remaining points are transformed correctly by your result.

If you don't want to work through the maths yourself, the resulting matrix is

$$M= \begin{bmatrix} 2 & -2 & 3 \\ 1 & 1 & 2 \\ 0 & 0 & 1\\ \end{bmatrix}$$

Since the only answer requires homogeneous coordinates, a $$3\times3$$ matrix inversion, as well as a $$3\times3$$ matrix multiplication, here's something simpler, not as tedious to compute, and also more geometrically intuitive (it also gives a better idea what a linear map can do, and what it cannot).

A linear $$2\times2$$ transformation obviously cannot translate the origin, for this we will need a translation. We can find the translation from the difference between the lower left vertices of the house (since both should lie at the origin of their coordinate systems). We see that $$(0,0)\rightarrow (3,2)$$, then the translation is $$(3,2)$$. We can move the stretched and rotated house back to the origin: so that the lower left vertex coincides with $$(0,0)$$ (the initial position of it) by translating with $$-(3,2)$$. We'll pick two 'nice' points (in the sense that they have $$0$$ for one of their components and $$1$$ for the other): $$(1,0)$$ and $$(0,1)$$. We can see from the image that $$(1,0) \rightarrow (5,3) - (3,2) = (2,1)$$ where the subtraction is necessary to move the transformed house back to the origin as already mentioned. Similarly: $$(0,1) \rightarrow (1,3) - (3,2) = (-2,1)$$. We want to find a matrix: $$M =\begin{bmatrix} a & b\\ c & d\\ \end{bmatrix}$$ such that $$M(1,0)^T = (2,1)^T$$ and $$M(0,1)^T = (-2,1)^T$$. But this is trivial, since we get $$(a,c) = (2,1)$$ and $$(b,d) = (-2,1)$$. Thus you have: $$v'=Mv+(3,2)$$, where $$v$$ is a point from the original house, and $$v'$$ is the transformed such. Note that it is easy to see that this is simply scaling + rotation (45 degrees) + scaling: $$M =\begin{bmatrix} 2 & -2\\1 & 1\\ \end{bmatrix} = \begin{bmatrix} 2 & 0\\0 & 1\\ \end{bmatrix} \begin{bmatrix} 1 & -1\\1 & 1\\ \end{bmatrix} \\= \begin{bmatrix} 2 & 0\\ 0 & 1\\ \end{bmatrix} \begin{bmatrix} \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}}\\ \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}}\\ \end{bmatrix} \begin{bmatrix} \sqrt{2} & 0\\ 0 & \sqrt{2}\\ \end{bmatrix}$$

The right scaling may be moved inside the left one (since the right is uniform scaling, hence commutative, or just a multiplication by the scalar $$\sqrt{2}$$, I just thought it's geometrically more intuitive this way).