Determining 2d transformation matrix with known constraints

1.1k Views Asked by At

I want to find a matrix A which transforms a vector between two arbitrary cartesian bases:

$A\cdot \vec{x}=\vec{x'}$

My understanding is that if I write $A$ as

\begin{bmatrix}a & b & c\\d & e & f\end{bmatrix}

and $\vec{x}$ as

\begin{bmatrix}x \\ y \\ 1\end{bmatrix}

then I can solve for $A$ by doing

$A = X' \cdot X^{-1} $

Where $X$ and $X'$ are matrices composed of vectors of known pairs of coordinates in each basis (e.g. $x_1, y_1$ and $x_1^`, y_1^`$).

It seems I need 3 such pairs; 6 inputs to solve for the 6 unknowns in $A$.

Counting on my fingers suggests that I need 4 input variables, however:

  1. x translation
  2. y translation
  3. 1 scale factor (since x and y scale are identical in this case)
  4. 1 rotation factor (rotation around the z plane)

I can't see how to unite these two ideas; is there a way to simplify $A$ given these constraints, so I only need two pairs of points to solve?

1

There are 1 best solutions below

3
On BEST ANSWER

Your finger count is correct. The general transformation matrix that you’re starting with represents an affine transformation with six degrees of freedom, but the since the scaling is uniform in the transformation you’re trying to construct, you’re really talking about a similarity, which has only four degrees of freedom. Two pairs of points should be sufficient to compute its matrix, which is of the form $$\mathtt A = \left[\begin{array}{c|c}s\mathtt R & \mathbf t\end{array}\right] = \begin{bmatrix}s\cos\theta&-s\sin\theta & t_x \\ s\sin\theta & s\cos\theta & t_y\end{bmatrix},$$ a composition of a scaled rotation and translation. By applying this template to the two pairs of points, you will get a system of linear equations in the four unique entries of $\mathtt A$. That is, the point $(x,y)$ and its image $(x',y')$ contribute the two constraints $$\begin{align} x' &= xs\cos\theta-ys\sin\theta+t_x \\ y' &= xs\sin\theta+ys\cos\theta+t_y\end{align}.$$ So, with two pairs of points, the unknown matrix elements are given by $$\begin{bmatrix}s\cos\theta \\ s\sin\theta \\ t_x \\ t_y\end{bmatrix} = \begin{bmatrix}x_1&-y_1&1&0 \\ y_1&x_1&0&1 \\ x_2&-y_2&1&0 \\ y_2&x_2&0&1 \end{bmatrix}^{-1} \begin{bmatrix}x'_1\\y'_1\\x'_2\\y'_2\end{bmatrix}.$$