简体   繁体   中英

Transform vector array in C++ Eigen library

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

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;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM