In short, unit quaternion is one way of representing 3D rotational transformation (or 3D orientation of a coordinate system). Its real part is cos (0.5 * theta) and its imaginary part is sin(0.5 * theta) * v where (theta, v) is an angle of rotation and an axis of rotation (in an unit vector) respectively; for the axis vector [x, y, z], we define v := xi + yj + zk.
For instance, let's say you rotate some vector around x axis by 1 rad. The corresponding quaternion is q = [cos(0.5), sin(0.5), 0, 0, 0] or more specifically, cos(0.5) + sin(0.5) i + 0 j + 0 k
Then you can use this quaternion q to rotate a 3D vector v around x axis by 1 rad with some special mathematical operation (option 1 is using matrix operation, option 2 is using complex number multiplication. see the one of the references below.)
If you want some materials to learn more about quaternion. I recommend these amazing videos from 3brown1blue:
it's not about quaternion but the linear algebra lectures of 3Brown1Blue could be very useful for this course in general, so I do recommend you to watch it
For now, in our code base, you can just use quaternion as the same way you use a rotation matrix.
For instance, let's say Eigen quaternion qAB is equivalent to a rotational matrix R_{A}{B} wherev_A = R_{A}{B} v_B; v_A denotes a 3D vector v expressed in frame A, and v_B denotes v expressed in frame B .
Then, in cpp code, you can use quaternion as follows
V3D v_A = qAB * v_B
Please note that this is not just a simple matrix-vector or vector-vector multiplication but rather a special operation for rotating a vector with an unit quaternion that is already implemented and overloaded by cpp * operator in Eigen library.
I hope this helps.
Please find a short description about unit quaternion here: the original discussion is https://github.com/CMM-22/a2/issues/5
TL;DR:
In short, unit quaternion is one way of representing 3D rotational transformation (or 3D orientation of a coordinate system). Its real part is
cos (0.5 * theta)
and its imaginary part issin(0.5 * theta) * v
where (theta, v) is an angle of rotation and an axis of rotation (in an unit vector) respectively; for the axis vector [x, y, z], we definev := xi + yj + zk
.For instance, let's say you rotate some vector around x axis by 1 rad. The corresponding quaternion is
q = [cos(0.5), sin(0.5), 0, 0, 0]
or more specifically,cos(0.5) + sin(0.5) i + 0 j + 0 k
Then you can use this quaternion
q
to rotate a 3D vector v around x axis by 1 rad with some special mathematical operation (option 1 is using matrix operation, option 2 is using complex number multiplication. see the one of the references below.)If you want some materials to learn more about quaternion. I recommend these amazing videos from 3brown1blue:
Also this webpage:
Other references are here
For now, in our code base, you can just use quaternion as the same way you use a rotation matrix.
For instance, let's say Eigen quaternion
qAB
is equivalent to a rotational matrix R_{A}{B} wherev_A = R_{A}{B} v_B
; v_A denotes a 3D vector v expressed in frame A, and v_B denotes v expressed in frame B .Then, in cpp code, you can use quaternion as follows
Please note that this is not just a simple matrix-vector or vector-vector multiplication but rather a special operation for rotating a vector with an unit quaternion that is already implemented and overloaded by cpp * operator in Eigen library. I hope this helps.