4

Getting started in the Eigen math library, I'm having trouble with a very simple task: transform a series of vectors using a quaternion. Seems everything I do results in no operator* found, or mixing an array with a matrix.

Eigen::Quaternionf rot = …;
Eigen::Array3Xf series = …;

// expected this to work as matrix() returns a Transformation:
series.matrix().colwise() *= rot.matrix();

// expected these to work as it's standard notation:
series = rot.matrix() * series.matrix().colwise();
series = rot.toRotationMatrix() * series.matrix().colwise();

// Also tried adding .homogeneous() as one example used it… no dice

2 Answers 2

5

Hm... not sure why you use an Array in your example. I guess you want to transform m 3-vectors by rot, right? You could use a 3xm Matrix for this.

How about

using namespace Eigen;
Quaternionf rot = ...;
Matrix<float,3,Dynamic> series = ...;

series = rot.toRotationMatrix() * series;
3
  • 1
    Thanks! Array was convenient for some vector-scalar additions not shown in the example. But Array is wrong, the object really is a matrix. Setting its type as such and calling .array() instead of .matrix() fixed the issue. It is odd that the return from .matrix() didn't work the same way… but whatever. Commented Aug 6, 2012 at 4:03
  • I just realised I meant to use .toRotationMatrix() instead of .matrix(). I don't think Arrays are required here. I've edited the original answer.
    – Jakob
    Commented Aug 13, 2012 at 15:01
  • I think series *= rot; suffices… it looks like my code uses an implicit conversion from Quaternionf to Matrix3f. Commented Aug 14, 2012 at 3:03
0

This might be a very blunt, but effective solution:

for (int vector = 0; vector < series.cols(); ++vector)
   series.col(vector) = rot * series.col(vector).matrix();

The point here is that somewhere, someone has to read your code. A simple for loop is often easiest to understand.

1
  • 1
    That's exactly what I did. I don't find that easier to read than the things I tried first. Commented Jul 30, 2012 at 10:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.