# Finding the transformation matrix to transform one triangle into another

I have 2 sets of 3 points: the "origin" and "destiny". Any ideas on how to find the best-fit transformation matrix that will convert the origin's points to destiny using (only) rotation, scaling and translation?

I know a way to solve that, which is creating a function that applies the 3 transformation to the origin points and calculate the distance of them to the destiny points; then I minimize this function. Any easier way?

## 1 Answer

A simple way to do this would be to canonicalize both triangles and then concatenate the transform that canonicalizes the "origins" with the inverse of the one that canonicalizes the "destinies".

For instance, a) apply a translation to move the point in the first pair to the origin; b) apply a rotation about an axis through the origin to move the point in the second pair onto the $z$-axis; c) apply a rotation about the $z$-axis to move the point in the third pair into the $y$-$z$-plane with non-negative $y$ coordinate. That moves all congruent triangles with identically numbered points into the same position.