Vector3d to Vector3i conversion eigen

What is the eigen way of converting vector3d to vector3i or vector2i.
Eg. how do i convert vector3d vec(3.555,0.4444,3.333) to vector3i and vector2i?
If worst comes to worst, you can just write a simple function to do it yourself, but it appears that the matrix classes have cast<type> functions in them.
object_of_float = expression_of_double.cast<float>();

https://eigen.tuxfamily.org/dox/AsciiQuickReference.txt
1
2
3
4
5
6
7
8
//// Type conversion
// Eigen                  // Matlab
A.cast<double>();         // double(A)
A.cast<float>();          // single(A)
A.cast<int>();            // int32(A)
A.real();                 // real(A)
A.imag();                 // imag(A)
// if the original type equals destination type, no work is done 


I assume that casting it to int truncates the number instead of rounding. If you want it to round, I imagine you'll have to do it yourself.

Casting a vector3 to a vector2 doesn't make much sense, though. What would you want to happen to the third dimension? It's not well-defined.
Last edited on
Topic archived. No new replies allowed.