I found a very good link about quaternions in Mathematica , but I don't know how to create a quaternion from a rotation matrix. Can anyone help me, please?
Update
I need this:
A rotation may be converted back to a quaternion through the use of the following algorithm. The process is performed in the following stages, which are as follows:
Calculate the trace of the matrix T from the equation:
T = 4 - 4x^2 - 4y^2 - 4z^2
= 4( 1 - x^2 - y^2 - z^2 )
= mat[0] + mat[5] + mat[10] + 1
If the trace of the matrix is greater than zero, then perform an "instant" calculation.
S = 0.5 / sqrt(T)
W = 0.25 / S
X = ( mat[9] - mat[6] ) * S
Y = ( mat[2] - mat[8] ) * S
Z = ( mat[4] - mat[1] ) * S
If the trace of the matrix is less than or equal to zero then identify which major diagonal element has the greatest value.
Depending on this value, calculate the following:
Column 0:
S = sqrt( 1.0 + mr[0] - mr[5] - mr[10] ) * 2;
Qx = 0.5 / S;
Qy = (mr[1] + mr[4] ) / S;
Qz = (mr[2] + mr[8] ) / S;
Qw = (mr[6] + mr[9] ) / S;
Column 1:
S = sqrt( 1.0 + mr[5] - mr[0] - mr[10] ) * 2;
Qx = (mr[1] + mr[4] ) / S;
Qy = 0.5 / S;
Qz = (mr[6] + mr[9] ) / S;
Qw = (mr[2] + mr[8] ) / S;
Column 2:
S = sqrt( 1.0 + mr[10] - mr[0] - mr[5] ) * 2;
Qx = (mr[2] + mr[8] ) / S;
Qy = (mr[6] + mr[9] ) / S;
Qz = 0.5 / S;
Qw = (mr[1] + mr[4] ) / S;
The quaternion is then defined as:
Q = | Qx Qy Qz Qw |
Comments
Post a Comment