c++eigenquaternions

EigenLib) Eigen::Quaterniond * 3.0 not working?


In C++, how do you multiply Eigen::Quaterniond with a scalar?

Eigen::Quaterniond q;
q.setIdentity(); // q can be any quaternion.
Eigen::Quaterniond q_new = q * 3.0;

just won't compile.


Solution

  • Eigen Quaternions were originally only intended to represent 3D rotations (there had been the idea to make general operations possible: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=560).

    To work-around your problem, you can access the coefficients of a quaternion using .coeffs():

    Eigen::Quaterniond q_new(q.coeffs() * 3.0);
    q.coeffs() += q_new.coeffs(); // etc.
    

    Edit regarding the comments about slerp:
    There is no need to manually compute a slerp between two quaternions, since it is supported directly by a function in QuaternionBase.