0
votes

For Eigen the arguments of .cross must be known at compile-time to be of size 3. (For example declaring matrices as Eigen::Matrix<float, 3, 1> ...

Now I was wondering if casting a dynamic matrix would hurt? For example:

Eigen::Matrix<float, -1, 1> a(3), b(3), c(3);
...
typedef Eigen::Matrix<float, 3, 1> vector3_t;
c = ((vector3_t)a).cross((vector3_t)b);

I can't really see a down-side of this. Is there maybe a hidden copy mechanism involved?

1

1 Answers

2
votes

Your solution will likely result in a copy, but since the operations themselves are all inlined and pretty simple, it might get optimized away almost completely (only way to be sure is to have a look at the assembly generated by your compiler).

To avoid the copy, you can try

typedef Eigen::Ref<const vector3_t> vector3_cr;
c = vector3_cr(a).cross(vector3_cr(b));

But is there a downside of declaring a, b, c as vector3_t from the beginning, in your case?