Essay record
C++: Implement Quaternion Multiplication with Eigen Library
- Record
- Essay / / 1 min read / 126 words
- Tags
- Unfiled
DISCLOSURE: Some links may be affiliate links. Details
**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:
