Rotating one 3d-vector to another only by using rotations about the coordinate axes.

885 Views Asked by At

If I have a vector v=(x,y,z) and would like to transform another vector u by using only rotations about the coordinate axes to be in the direction of v, how can I find required angles and the order of applying the rotations to align u with v. I my case u is initially directed along one of the basis vectors.

For example if v=(1,1,1) and u=(1,0,0) I can find the angle between the v and z axis to be 54.7 Deg and the angle that v projection onto xy plane makes with x axis is 45 Deg. Now using the rotation matrices to rotate u first about y axis and then about z axis aligns the u vector with v.

uv = rotz(45)*roty(54.7)*u'

uv will be aligned with v ( rotz(45) and roty(54.7) are corresponding rotation matrices about y and z axis) The above procedure seems rather cumbersome and not general, also if I switch rotation sequence it will not work.

Answers with octave/matlab example/implementations are welcome.

Here is what I have so far in octave

% initial vector
ux = [1 0 0];
%uy = [0 1 0]';
%uz = [0 0 1]';

% for example, vector to align to
v = [1 1 1];

% find a/b/c angles for rotation matrices
% and sequence of operations
 ...

rotx = rotv([1,0,0],a*pi()/180);
roty = rotv([0,1,0],b*pi()/180);
rotz = rotv([0,0,1],c*pi()/180);

% rotate the initial vector to be aligned with v
rotmat = % rotx*roty*rotz rotation sequence ?
uv=rotmat*ux';


% check the alignment 
th = acosd(dot(v,uv)/(norm(v)*norm(uv)))