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
    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]\ .