C++: Implement Quaternion Multiplication with Eigen Library
Problem: I’m using Eigen::Quaterniond, the built in Quaternion structure for the Eigen library. Unfortunately, it looks like the standard * operator performs normal multiplication, not the special quaternion multiplication required by an actual quaternion. How can I implement the special function to multiply a quaternion by a quaternion?
Solution: First, notice that your quaternion is composed of two parts – a scalar and a vector. With Eigen::Quaterniond, you can access these parts with myQuaternion.w() and myQuaternion.vec() respectively.
According to Wikipedia, the formula for multiplying a quaternion by a quaternion is as follows:
So, to implement this in C++, you might write something like this: