[Math] Find 2D affine transform matrix given a pair of points

affine-geometrygeometrylinear algebramatricestransformation

I have the coordinates of two points in an initial 2d coordinate system and the corresponding coordinates in a target system. Is is possible to determine the affine transform matrix from these values?

Since there are 6 unknowns, I would assume 2 points are not enough.

$
\begin{bmatrix}x' & y' & 1\end{bmatrix} =
\begin{bmatrix}x & y & 1\end{bmatrix}
\begin{bmatrix}a & b & 0 \\ c & d & 0 \\ t_x & t_y & 1\end{bmatrix}
$

But intuitively I don't quite understand why 2 points would not be enough.

Consider the 2 finger "pinch to zoom" gesture you can use on touch screens. Isn't that exactly this case? You have the coordinates of the fingers when they first touched the screen and you have their current coordinates. And seemingly it's possible to transform the content in a way that always maps the originally touched locations to the current finger positions and scales, translates, rotates the rest accordingly.

Best Answer

Two points is not enough information. There is a flaw in your argument about the pinch gesture. You could scale by whatever value you wanted in the direction perpendicular to the pinch, and the transform would still work. So, the transform is not fully determined by the two pairs of points.

The transform used in the pinch gesture is a translation+rotation+scaling, where the scaling is uniform. So, there are only four unknowns -- the x and y translations, the rotation angle, and the scale. You can determine these four quantities from the two pairs of points you get from the gesture.

Saying it another way, the "pinch" transform does not involve any secondary scaling (where one direction is scaled differently from the other), and it doesn't involve any skewing of axes. So, compared to a general 2D affine transform, two parameters are missing, and only four are left.