Search code examples
c++eigenquaternions

Eigen product of the zero quaternion and any vector is not zero, is this a bug?


I'm using Eigen 3.3.7 and its quaternions to perform transformations on a set of vectors.

I needed to perform the product of a quaternion (that may be the zero-quaternion) with a vector. The problem is that when the quaternion IS the zero quaternion (zero real and vector parts), the value returned is the vector itself.

What I have understood by the Hamilton product definition is that, if the quaternion is the zero-quaternion, the product should return the zero-vector. Am I wrong?

The following snippet shows the issue, I was expecting vector sv to be the all zero, but it is not. Is this a bug?

Eigen::Quaterniond q{0.0, 0.0, 0.0, 0.0};
Eigen::Vector3d v{1.0, 2.0, 3.0};
auto sv = q * v;

Cheers and thanks.


Solution

  • I've to admit that the doc of this operator* is not crystal clear, but it is semantically equivalent to:

    q.toRotationMatrix() * v
    

    because Eigen::Quaternion has been designed to represent rotation only. In your case, since the null quaternion q is not unitary, it does not represent any rotation, and the return value is undefined.

    See bug 560 for further details and discussions.