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

Most compact code to upsize a fixed-sized vector

Tags: None
(comma "," separated)
arennuit
Registered Member
Posts
28
Karma
0
Hi all,

I have a Eigen::Vector2d which I would like to upgrade into a 3d vector Vector3d within computations. Currently what I am writing is:

Code: Select all
Eigen::Vector2d v_2d;
...
Eigen::Vector3d p_3d = <some operation> * Eigen::Vector3d(v_2d.x(), v_2d.y(), 0.0);


Is there a more compact way to code the same behavior?

Thanks,

Antoine.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
If you want to extend with 0, then remove the respective content:

p_3d = <some operation>.leftCols<2>() * v_2d;

If you want to extend with 1, then there is v_2D.homogeneous();

And finally, you can also create the 3D vector as:

Vector3d v3;
v3 << v2, 0;
arennuit
Registered Member
Posts
28
Karma
0
Very relevant, thanks!


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]