This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Vector3d to Vector3i conversion

Tags: None
(comma "," separated)
rumbadinesh
Registered Member
Posts
2
Karma
0

Vector3d to Vector3i conversion

Thu Jun 25, 2020 5:48 am
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?
andrew-dy
Registered Member
Posts
15
Karma
0

Re: Vector3d to Vector3i conversion

Fri Jun 26, 2020 11:55 pm
This code casted your example double vector to an integer vector for me:
Code: Select all
    Eigen::Vector3d vec(3.555,0.4444,3.333);
    Eigen::Vector3i i_vec = vec.cast <int> ();
    std::cout << i_vec;

Source: https://stackoverflow.com/a/53497636/13784831

This code "selects" the first 2 elements in the vector:
Code: Select all
    Eigen::Vector2d vec_2 = vec.block(0, 0, 2, 1);
    std::cout << vec_2;

Reference: https://eigen.tuxfamily.org/dox/group__ ... tions.html

Combine these to convert the first two elements of a double vector to a 2-element integer vector:
Code: Select all
    Eigen::Vector2i i_vec_2 = vec.block(0, 0, 2, 1).cast <int> ();
    std::cout << i_vec_2;


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]