# 3d transformation two triangles

I have two triangles in 3d. I need to calculate transformation matrix(3X3) between two triangles in 3D.

1)How can I calculate the transformation matrix(rigid) while fixing one of the points to the origin(to get rid of the translation part)?

2)How does it affect if the deformation is non rigid?

-

1) The transformation matrix is in general 4x4: $$\begin{bmatrix} R&t\\ 0&1\\ \end{bmatrix}$$ with $R$ being a 3x3 rotation matrix and $t$ being a translation vector.

Let $x_1,x_2,x_3\in\mathbb{R}^3$ be the first triangle and $\bar{x}_1,\bar{x}_2,\bar{x}_3\in\mathbb{R}^3$ the second one.

Then following Arun et al. 1987, we get:

$$c = \frac{1}{3}(x_1 + x_2 + x_3), \quad \bar{c} = \frac{1}{3}(\bar{x}_1 + \bar{x}_2 + \bar{x}_3), \quad\text{(calculate centroids)}$$

$$y_i = x_i-c, \quad \bar{y}_i = \bar{x}_i-\bar{c}, \quad\text{(subtract centroids from points)}$$

$$H = y_1\bar{y}_1^\top + y_2\bar{y}_2^\top + y_3\bar{y}_3^\top, \quad U\cdot\Sigma\cdot V^\top = H \quad\text{(singular value decomposition)}$$

$$R = V U^\top, \quad t = c - R\bar{c}$$

2) The solution above is a least-squares fit, so if there is a tiny deformation this should not affect the result too much. It is hard to say more about it, if we don't know what kind of deformation we are expecting (scale change only, affine deformation, or something else).

-
Can you clarify how $H$ is actually formed? It's difficult to see how you can write a sum of the multiplication of row/column vectors as a 3 x 3 matrix. I also think your expression for $t$ is wrong. referring to Arun et al 1987, it is suggested that $R = V U^\top, \quad t = \bar{c} - Rc$ –  Matt Esch Dec 21 '12 at 17:19
Just to confirm. Arun et al consider, their vectors to be column vectors, so you're actually computing $H = Y \cdot \bar{Y}^\top$ where $Y$ is $$y_1, y_2, y_3$$ as augmented column vectors and likewise for $\bar{Y}$. If the real transformation is not rigid this will give you the least squares solution, i.e. it minimises the square of the distance between the points. –  Matt Esch Dec 24 '12 at 10:03
Yes, you are right, I meant the outer product. This was a typo/error (fixed now). –  Hauke Strasdat Jan 2 '13 at 22:12

Let the two triangles be $(O,A,B)$ and $(O,A', B')$, put ${\bf a}:=OA$, $\,{\bf b}:=OB$, and similarly for $A'$, $B'$. Then you are looking for a linear transformation $T:\ {\mathbb R}^3\to{\mathbb R}^3$ such that $T{\bf a}={\bf a}'$, $\ T{\bf b}={\bf b}'$. In the first place such a transformation is not uniquely determined. In ${\mathbb R}^3$ you can prescribe the images ${\bf a}_i'$ of three linearly independent vectors ${\bf a_i}$ in order to determine a linear map $T$ uniquely.

Maybe there are extra circumstances present in your situation. For instance, the two triangles might be euclidean congruent to begin with, and $T$ should be a rotation. In this case the conditions $$T{\bf a}={\bf a}', \quad T{\bf b}={\bf b}', \quad T({\bf a}\times{\bf b})={\bf a}'\times {\bf b}'$$ determine a certain rotation $T$ (whence the matrix of $T$ with respect to the standard basis) uniquely. To prove this, consider the three vectors ${\bf a}$, ${\bf b}$, ${\bf a}\times{\bf b}$ as a new basis of ${\mathbb R}^3$.

-