0
$\begingroup$

I've have two vectors A and B. I want to rotate both of them by the same angle until A is "upright" (has only a positive y component). Is it possible to calculate B without using functions like sin or tan?

I'm currently working on a game which solves this by calculating A's angle and rotating B by this angle. I hoped that there would be a more efficient way to do this to save some precious CPU-time.

Is this even possible? Or am I just to blind to see the obvious solution?

Thank you :-) Marek

edit: It's a planar problem. I've tried to illustrate it:

enter image description here

  • 0
    Wait, is this in the plane or in space? Could you probably draw a picture that demonstrates what you want to happen?2011-09-24
  • 2
    Well yeah. Just replace the $\sin$ and $\cos$ in the [rotation matrix](http://en.wikipedia.org/wiki/Rotation_matrix) with the more direct computations: $$\cos\theta=\frac{\vec{A}\cdot\vec{e}_2}{\|\vec{A}\|},\quad\sin\theta=\frac{( \vec{A}\times\vec{e}_2)\cdot\vec{e}_3}{\|\vec{A}\|}$$2011-09-24
  • 1
    Ah, well: $$\frac1{\sqrt{a_1^2+a_2^2}}\begin{pmatrix}a_2&-a_1\\a_1&a_2\end{pmatrix}$$ is the matrix you need...2011-09-24
  • 0
    Thanks anon, this is basically what I was looking for but now I struggling with solving this equations (I'm sorry, I seem to have forgotten all of my vector knowledge). I know that $\|\vec{A}\|=\sqrt{(A_1)^2+(A_2)^2}$ but how do I calculate $\vec{A}\cdot\vec{e}_2$ or $(\vec{A}\times\vec{e}_2)\cdot\vec{e}_3$. More exactly: What is $\vec{e}_n$? I'm sorry to brother you with such basic questions :(2011-09-24
  • 0
    Oh, thank you J.M. This seems to be exactly what I was looking for. I'm going to try this out.2011-09-24
  • 0
    marekventure: $\vec{e}_2=(0,1,0)$ and $\vec{e}_3=(0,0,1)$; they're basis vectors. Doing the calculations and plugging them into the matrix gives what J.M. put down.2011-09-25

1 Answers 1

1

If $T$ rotates the plane by an angle $\theta$ in the counter-clockwise direction then its matrix is $$\left[\matrix{c & -s \cr s& c \cr}\right]\ ,$$ where $c:=\cos\theta$ and $s:=\sin\theta$. Now you want $T$ such that $$\left[\matrix{c & -s \cr s& c \cr}\right]\left[\matrix{a_1 \cr a_2 \cr}\right]\ =\ \left[\matrix{0 \cr \sqrt{a_1^2+a_2^2} \cr}\right]\ .$$ Solving this for $c$ and $s$ one obtains $$c={a_2\over \sqrt{a_1^2+a_2^2}}\ ,\quad s={a_1\over\sqrt{a_1^2+a_2^2}}\ .$$ The coordinates of the point $b':=T\> b$ are then given by $$\left[\matrix{b_1' \cr b_2' \cr}\right]=\left[\matrix{c & -s \cr s& c \cr}\right]\ \left[\matrix{b_1 \cr b_2 \cr}\right]\ .$$