Consider tranformation which turns one aligned rectangle to another:

This tranformation can be written in matrix form in the following way

where
$a_i=a_{ii}=\frac{x'_{i1}-x'_{i2}}{x_{i1}-x_{i2}}$
$b_i==\frac{x_{i1}x'_{i2}-x_{i2}x'_{i1}}{x_{i1}-x_{i2}}$
and
$a_{12}=a_{21}=0$
i.e. transform matrix is diagonal.
My question is: what about arbitrary matrix? What 2 geometric figures defines it? Is this a pair of two arbitrary quadrangles?
If "yes", then what is the formula, relating angle coordinates to matrix coefficients?
How is it extrapolated to multidimensional?
UPDATE
I realized, that the number of equations in each transformation is $N$, the dimension of space, and the number of unknowns is $N^2+N=N(N+1)$ where $N$ is the number of translation column elements and $N^2$ is the number of linear matrix elements. Hence to make the system complete, we need $N(N+1)/N = (N+1)$ sample pairs of points.
So in the case of 2D we need to provide 2 arbitrary triangles to define transform.
Where to find a formula?