I would like to express 3D rotation using unit quaternions. I want to do this as I do not want to battle Eurler angle limitations and singularities ( gimble lock ). As a precursor to my quest, I've watched the following youtube video, and actively tried to understand several of these posts:
Extracting Yaw from a Quaternion
Quaternion representation of rotations
However, I am having a very hard time of understanding how to apply the w,i,j,k components to calculate the basic rotations around the x, y, and z axis ( as mentioned in the linked video at 11:36 ).
Here is some sample data that I received from MATLAB :
a = 0.1790, b = -0.5520, c = -0.3656, d = -0.7277
a = 0.1779, b = -0.5533, c = -0.3693, d = -0.7251
Using the above data, I'd like to determine the angle $\theta$ $\phi$ $\beta$, or alike in the Euler land, yaw, pitch, and roll. From what I've learned, this ought to hold true for unit quaternions:
$a^2 + b^2 + c^2 + d^2 = 1$
If I run it on the above output, I get the following results:
$0.1790^2 + -0.5520^2 + -0.3656^2 + -0.7277^2 = 0.9999557$
$0.1779^2 + -0.5533^2 + -0.3693^2 + -0.7251^2 = 0.9999418$
The numbers are close enough to make the rule true.
After looking at the selected answer for the first referenced stack post, the author makes this comment:
If you want to create a quaternion that only rotates around the y axis, you zero out the x and z axes and then re-normalize the quaternion:
b = 0;
d = 0;
double mag = sqrt( a * a + c * c);
a /= mag;
c /= mag;
double ang = 2 * acos(a);
If I plugged in the data I presented earlier, this would yield the following :
$a = 0.1790 / sqrt(0.1790^2 + -0.3656^2)$
$2 * acosd(0.4397) = 127.8305$
$a = 0.1779 / sqrt(0.1779^2 + -0.3693^2)$
$2 * acosd(0.4340) = 128.5566$
This in line with the referenced video, which draws this conclusions :
$(a,b,c,d)$ = $(cos\theta/2, v_1 sin\theta/2, v_2 sin\theta/2, v_3 sin\theta/2)$
My questions:
Is the above correct?
Would I follow the same process to identify the rotation around x and z axis? (sqrt( a * a + b * b)) and sqrt( a * a + d * d), respectively ?
Using the provided data would really help me understand.