[Math] Using quaternions to represent an affine transformation

algebraic-geometrygeometryquaternions

I have never used quaternions, so before trying on my problem I would like to know whether this is a good idea:

I want to interpolate an affine transformation: I have a set of points in a first 2D image I1 that are transformed by an affine transformation T into points in image I3. I want to introduce an intermediate image I2 between I1 and I3 and I would like to find out the transformation T' such that we should apply T' to the points of I1 to get to I2. Intuitively, T' should be "half" of the transformation T.

I read on a forum:
1-Transform the affine transformation matrix into quaternions
2- Use the Slerp interpolation on these quaternions
3- Convert them back to a matrix

Would that work on my 2D setting?

Best Answer

From my cursory reading of what slerp interpolation is, it sounds like it only deals with rotations, so it may or may not be helpful for general affine transformations.

It sounds like you wish to decompose the transformation $ax+b$ (where $a\in GL(\Bbb R,2)$ is the skewing and $ b\in \Bbb R^2$ is the translation, into a transformation $cx+d$ such composing $cx+d$ with itself results in the full $ax+b$ transformation, and just one application of $cx+d$ is the halfway point.

That would have to satisfy this: $c(cx+d)+d=ax+b$. Thus $c^2=a$ and $(c+I_2)d=b$.

Now there are formulas to compute the square root of some $2\times 2$ matrices, so using that you would be able to find a $c$ such that $c^2=a$. If additionally $c+I_2$ is invertible, then you would be able to find $d=b(c+I_2)^{-1}$, and that would furnish a $T'$ that satisfies $T'(T'(x))=ax+b$, and that seems like "half" of $T$ to me.

I can't see immediately what the conditions on $a,b$ allow this construction to work. (Edit: Marek has added insightful analysis along these lines in the comments, and shown that even a rotation by $\pi$ needs some special care.)


On the other hand, if "finding the square root of $T$" is too elaborate for you, you can always just split $ax+b$ into $ax$ and $x+b$.

Or if you prefer to avoid the fixed point in the first transformation, you can do $ax+b/2$ then $x+b/2$.