Essay - Published: 2016.04.08 |
DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)
**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:
The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.