anti anti - 1 month ago 6
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

quaternionf
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>'


in:

\eigen\src\Geometry\Quaternion.h


What am I missing here?

Thanks.

Answer

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>());
Comments