anti anti - 3 months ago 9
C++ Question

Eigen::Quaternionf, how can I access the values?

I am trying to use Eigen in an existing project, and am stuck.

I am creating a

from a matrix, like so:

Eigen::Quaternionf quats(path.block(0, 0, 3, 3));

The matrix is valid, and this construction should work.

When i try to call the x,y,z,w values though, like this:

float test = quats.x();

It will not compile, giving me:

use of undefined type 'Eigen::internal::quaternionbase_assign_impl<MatrixDerived,-1,-1>'



What am I missing here?



The problem is not is quats.x() but in the initialization:

Eigen::Quaternionf quats(path.block(0, 0, 3, 3));

You must tell Eigen that your are passing a 3x3 matrix at compile time:

Eigen::Quaternionf quats(path.block<3,3>(0, 0));

or even:

Eigen::Quaternionf quats(path.topLeftCorner<3,3>());