rotate a Vector to reach orthogonality with another vector

c++, geometry

Solution

I would do that in this way:

    A = V1xV2; //Cross product, this gives the axis of rotation
    sin_angle =  length(A)/( |V1| |V2|); //sine of the angle between vectors

    angle = asin(sin_angle);
    A_n = normalize(A);

Now you can build a quaternion with angle and A_n.

    q = (A_n.x i + A_n.y j + A_n.z k)*sin(angle/2) + cos(angle/2);

And use these formulas to get your euler angles.

Problem

I have 2 vectors `(V1{x1, y1, z1}, V2{x2, y2, z2})` , and I want rotate `V1` around X-Axis, Y-Axis and Z-Axis to be parallel to `V2`. I want to find 3 rotation angles. Is there any general formula I can use to find them?

Original source