0

I'd like to perform rotation from one vector to the other. I have two formulaes to get sin(X) and cos(X), X being the rotation angle, but I can't see where they come from :

denom = a * a + b * b;
sin(X) = ( b * ta - a * tb ) / denom;
cos(X) = ( a * ta + b * tb ) / denom;

Can somebody help me to clear this out ?

Thanks

CTZStef
  • 144
  • Are you familiar with the formulas for getting the lengths of the sides of a right triangle? The denom variable is a big hint. The numerators are not familiar to me, but I'm guessing they are due to a transformation matrix. – abiessu Aug 14 '13 at 14:58
  • @abiessu, sure, but why keep it to the square ? Numerators are what puzzle me the most... – CTZStef Aug 14 '13 at 15:01
  • I'm not certain on why it is still squared, but the formulas have been correctly identified in the answer by Hagen von Eitzen. – abiessu Aug 14 '13 at 15:03

1 Answers1

3

The rotation would be $$ \begin{pmatrix}t_a\\t_b\end{pmatrix}= \begin{pmatrix}\cos X&\sin X\\-\sin X&\cos X\end{pmatrix}\begin{pmatrix}a\\b\end{pmatrix}$$ or $t_a=a\cos X+b\sin X$, $t_b=b\cos X-a\sin X$. Solving for $\sin X, \cos X$ gives the equations you have