$LastChangedDate: 27-Juil-2011 $

# CL_rot_defRot2Ax

Determination of 2 successive rotations

## Calling Sequence

       [qa, angsa, Inok] = CL_rot_defRot2Ax(u, v, axis1, axis2, [numsol=1])
       [qa, angsa, qb, angsb, Inok] = CL_rot_defRot2Ax(u, v, axis1, axis2, numsol=2)

## Description

- Computes the rotation, combination of 2 rotations around 2 axes, that transforms a vector (u) into another vector (v).

  The rotation is returned as a quaternion, and the corresponding rotation angles are also returned.

  There are two solutions (in usual situations):

  (qa, angsa): solution such that the second rotation angle is minimal.

  (qb, angsb): solution such that the second rotation angle is maximal.

  axis1 and axis2 can either be vectors (3xN) or axes numbers (1 for x-axis, 2 for y-axis or 3 for z-axis). The axes should be perpendicular to one another. If they are numbers, the vectors u and v must be given in the frame where the axes are basis vectors (coordinates = [1;0;0], [0;1;0], or [0;0;1]).

  Indices for which the rotation doesn't exist or is not uniquely defined are returned in Inok.

- Notes:

  - If no rotation exists, the rotation computed is such that the image of u is as close to v as possible.

  - If the axes are given as vectors, the coordinates are those of the vectors not considering the effect of the rotations.

  - If the axes are colinear, the results are set to %nan.

## Parameters

u:

  Vector to be rotated (3xN or 3x1)

v:

  Desired image of u by the rotation (3xN or 3x1)

axis1:

  Axis vector (3xN or 3x1) or axis number (1x1) for the first rotation

axis2:

  Axis vector (3xN or 3x1) or axis number (1x1) for the second rotation

numsol:

  (optional, integer) Number of solutions returned: 1 or 2. Default is 1

qa:

  Quaternion for the 1st solution (dim N)

angsa:

  Rotation angles for the 1st solution (2xN)

qb:

  Quaternion for the 2nd solution (dim N)

angsb:

  Rotation angles for the 2nd solution (2xN)

Inok:

  Indices for which the rotation is not uniquely defined, or the desired target vector cannot be reached

## Authors

- CNES - DCT/SB

## See also

- CL_rot_defQuat

- CL_rot_defRotVec

- CL_rot_defRot1Ax

## Examples

    // Example1: X axis then Y
    u = [ 1 ; 2 ; 3 ];
    v = [ 3 ; 1 ; 2 ];
    n1 = 1;
    n2 = 2;
    [qa, angsa, Inok] = CL_rot_defRot2Ax(u, v, n1, n2);
    // Check results :
    v2 = CL_rot_rotVect(qa,u) // == v

    // Example2: axes = vectors
    u = [ 1 ; 2 ; 3 ];
    v = [ 3 ; 1 ; 2 ];
    axis1 = [-2;3;4];
    axis2 = [1;0;1];
    [qa, angsa, qb, angsb, Inok] = CL_rot_defRot2Ax(u, v, axis1, axis2, numsol=2);
    // Check results :
    v2a = CL_rot_rotVect(qa,u) // == v
    v2b = CL_rot_rotVect(qb,u) // == v