my problem is based on this code: https://pastebin.com/EqSemWY2
There they estimate an affine transformation matrix of an overdetermined linear equation. But they do not do it with an iterative approach but with scalar and cross product.
They basically do the same as in Calculate Rotation Matrix to align Vector A to Vector B in 3d? (2D case) but with more than 1 point in every domain.
Here is what they do: $source = \begin{pmatrix}x1\\y1\\x2\\y2\\...\\xn\\yn\end{pmatrix}$ $dest = \begin{pmatrix}x1\\y1\\x2\\y2\\...\\xn\\yn\end{pmatrix}$
$source_i = \begin{pmatrix}xi\\yi\end{pmatrix}$ $dest_i = \begin{pmatrix}xi\\yi\end{pmatrix}$ of the above matrix.
$a = \frac{<source, dest>}{\left\lVert source \right\rVert ^2 }$
$b = \frac{\sum_i source_i \times dest_i}{\left\lVert source \right\rVert ^2}$
$A = \left[ {\begin{array}{cc} a & b \\ -b & a \\ \end{array} } \right] $
Now A is the rotation + scale. The translation is calculated with the mean of the difference of the x and y values. That is clear.
I can also understand the calculation for the 1 point case. Because then:
$a = s_1*cos(\alpha) = \frac{\left\lVert dest \right\rVert}{\left\lVert source \right\rVert} * \frac{<source, dest>}{\left\lVert dest \right\rVert \left\lVert source \right\rVert} = \frac{<source, dest>}{\left\lVert source \right\rVert ^2 } $
$b = s_2*sin(\alpha) = \frac{\left\lVert dest \right\rVert}{\left\lVert source \right\rVert} * \frac{source \times dest}{\left\lVert dest \right\rVert \left\lVert source \right\rVert} = \frac{source \times dest}{\left\lVert source \right\rVert ^2 } $
But why does it work with more than 1 point? Is it a kind of mean?