0
$\begingroup$

I have a matrix which performs a 2D rotation around any given center. Using homogenous coordinates, I have the matrices:

$$ T = \begin{pmatrix} 1 & 0 & C_x \\ 0 & 1 & C_y \\ 0 & 0 & 1 \end{pmatrix}$$

where $C_x$ and $C_y$ are the coordinates of the rotation center, and

$$ R = \begin{pmatrix} \cos(\theta) & -\sin(\theta) & 0 \\ \sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 1 \end{pmatrix}$$

Now I can obtain the matrix $X = TRT^{-1}$, which translates everything to the origin, rotates and then translates back to the given center.

My question is, given $X$, is it possible to find $C_x$, $C_y$ and $\theta$ ?

At first blush, I'd think so, since (where $c$ and $s$ are the cossine and sine, respectively) $$ X = \begin{pmatrix} c & -s & C_x(1-c)+C_ys \\ s & c & -C_xs+C_y(1-c) \\ 0 & 0 & 1 \end{pmatrix} = \begin{pmatrix} c & -s & \beta \\ s & c & \gamma \\ 0 & 0 & 1 \end{pmatrix} $$

It then becomes a simple matter of solving for $C_x$ and $C_y$. But the result I'm finding is

$C_y = \dfrac{\beta+C_x(c-1)}{s}$

$C_x = \dfrac{C_y(c-1)-\gamma}{s}$

However, working on from here, the results I'm getting give the center as a function of the angle of rotation, which would mean that, as the rotation occurs, the center is moving, which is obviously incorrect.

So, how can this be done?

I have seen the these questions (1, 2 and 3) but they all deal with X = TRS (S = scale). My question actually seems simpler than these, but I just can't figure it out.

$\endgroup$
  • 1
    $\begingroup$ A translation is not linear. Your matrix $T$ is not what you think it is $\endgroup$ – krirkrirk Mar 13 '15 at 15:22
  • $\begingroup$ $T.0_3=0_3$ ($T$ is linear, a translation is not, as indicated by krirkrirk) $\endgroup$ – anderstood Mar 13 '15 at 15:53
  • $\begingroup$ $T$ works fine on vectors with homogenous coordinates. Translations are affine, that is the point of using homogeneous coordinates. At what part of the above would it matter that the OP assumed linearity? $\endgroup$ – mvw Mar 13 '15 at 15:57
1
$\begingroup$

Starting with the upper right block from the comparison $X = (..)$: \begin{align} X_{13} &= C_x (1-c) + C_y s= \beta \\ X_{23} &= -C_x s + C_y(1-c) = \gamma \end{align} and rewriting it as matrix equation with unknowns $C_x$, $C_y$: $$ \left( \begin{matrix} 1-c & s \\ -s & 1-c \end{matrix} \right) \left( \begin{matrix} C_x \\ C_y \end{matrix} \right) = \left( \begin{matrix} \beta \\ \gamma \end{matrix} \right) $$ Using matrix inversion I get $$ \left( \begin{matrix} C_x \\ C_y \end{matrix} \right) = \left( \begin{matrix} \frac{1}{2} & -\frac{s}{2(1-c)} \\ \frac{s}{2(1-c)} & \frac{1}{2} \end{matrix} \right) \left( \begin{matrix} \beta \\ \gamma \end{matrix} \right) \quad (*) $$ and $$ \theta = \arccos c = \arcsin s \quad (**) $$

So a given $X$ gives $c = X_{11}, s = X_{21}, \beta = X_{13}, \gamma = X_{23}$ and can be used with the above equations to yield $C_x, C_y, \theta$, if $c \ne 1$.

The case $c = 1$ is for $X = I$, $\theta = 0$ where we do not need this transformation.

Example:

Given this matrix $X$: $$ X = \left( \begin{matrix} 0.70712315999226 & -0.70709040200144 & 2.707024886019803 \\ 0.70709040200144 & 0.70712315999226 & -0.53555028397966 \\ 0 & 0 & 1 \end{matrix} \right) $$ we read \begin{align} c &= 0.70712315999226 \\ s &= 0.70709040200144 \\ \beta &= 2.707024886019803 \\ \gamma &= -0.53555028397966 \end{align} Using equation $(**)$ gives $\theta = 0.785375$ and using equation $(*)$ gives $C_x = 1.999999999999993$ and $C_y = $2.999999999999991.

And indeed I used a translation matrix $T$ with $C_x =2$ and $C_y = 3$ and a rotation matrix with $\theta = \pi / 4$ to generate $X = T\, R \, T^{-1}$.

$\endgroup$
  • $\begingroup$ I appologize, but I don't understand what you did here. What is the initial 2x2 matrix? Where's the translation part? Yes, in a simple rotation matrix $X_{11} = X_{22}$ area always equal to the cosine and the other diagonal are equal to $\pm\sin$, but this question deals with more than this. Or am I missing something? $\endgroup$ – Wasabi Mar 13 '15 at 16:24
  • $\begingroup$ I added an example. I hope it gets clear. $\endgroup$ – mvw Mar 13 '15 at 16:39
  • $\begingroup$ Yes, thank you. I realize now my error was mostly conceptual. I noticed that the values of $C_x$ and $C_y$ were going to be functions of $\cos$, $\sin$, $\beta$ and $\gamma$ and went "wait, if the center is a function of $\cos$ and $\sin$, won't its value change for different angles?" But of course not, since $\beta$ and $\gamma$ are aliases to functions of $\cos$ and $\sin$, so internally the $\cos$ and $\sin$'s cancel out. Many thanks for the help. $\endgroup$ – Wasabi Mar 13 '15 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.