Rotation transforming 2 vectors into 2 vectors
[q,Inok] = CL_rot_defRotVec(u1,v1,u2,v2)
Computes the rotation that transforms 2 vectors into 2 vectors.
Except for possible scale factors and vector adjustments, the rotation R is such that:
R(u1) = u2 and R(v1) = v2
The rotation R is returned as a quaternion (q). In practice, the rotation is determined such that (assuming the vectors not aligned):
R(u1/||u1||) = u2/||u2||
R(u1^v1/||u1^v1||) = u2^v2/||u2^v2||
so that the angular separations between u1 and v1, and u2 and v2 do not matter (provided they remain in ]0,pi[).
Notes:
If (u1 and v1) or (u2 and v2) are colinear, then the rotation is not uniquely defined or may not exist, and the corresponding indices are returned in Inok. In that case, the returned rotation is the rotation that transforms u1 into u2 about an axis perpendicular to the plane (u1,u2) which is the one with the smallest rotation angle. If additionnaly u1 and u2 are colinear, then the rotation is either the identity or a 180 degree rotation about an axis perpendicular to u1.
Use note:
The function can be used for frame determination when 2 vectors are known in 2 different frames:
- u1,v1: coordinates relative to frame 1
- u2,v2: coordinates relative to frame 2
=> q = CL_rot_defRotVec(u1,v1,u2,v2) gives the rotation that transforms the basis vectors of frame2 into the basis vectors of frame 1.
The frame transformation matrix M from Frame 1 to Frame 2 is then: M = CL_rot_quat2matrix(q'), and is such that: u2 = M*u1 and v2 = M*v1
First vector (3xN or 3x1)
Second vector (3xN or 3x1)
Desired image of u1 by the rotation (3xN or 3x1)
Desired image of v1 by the rotation (3xN or 3x1)
Quaternion that defines the rotation (dim N)
Indices for which u1,v1,u2,v2 do not define a unique rotation.
CNES - DCT/SB