How do you make a matrix out of vectors in eigen?

2019-02-12 11:51发布

问题:

I have four column vectors. I need to append them to make a four by four matrix. Is there a constructor or something for that?

回答1:

You can also append them using the comma initializer syntax:

m << v1, v2, v3, v4;

The matrix m mus have been properly resized first.



回答2:

A quick check on the docs:

Vector4f v1(1,0,0,0);
Vector4f v2(0,1,0,0);
Vector4f v3(0,0,1,0);
Vector4f v4(0,0,0,1);
Matrix4f m;

m.row(0) = v1;
m.row(1) = v2;
m.row(2) = v3;
m.row(3) = v4;

std::cout << m << std::endl;

output:

1,0,0,0
0,1,0,0
0,0,1,0
0,0,0,1