Rotate a vector to achieve orthogonality with another vector

I have 2 vectors (V1{x1, y1, z1}, V2{x2, y2, z2})and I want to rotate V1around the X axis, the Y axis and the Z axis parallel to V2. I want to find 3 rotation angles. Is there a general formula that I can use to find them?

+3
source share
2 answers

I would do it like this:

    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 an 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 Euler angles.

+3
source

, , . , , OpenFOAM: http://github.com/OpenFOAM/OpenFOAM-2.1.x/blob/master/src/OpenFOAM/primitives/transform/transform.H#L45

, OpenFOAM vector & , ^ - -, * - . sqr , magSqr a vector (.. v&v).

+1

All Articles