Creating an Eigen matrix from an array with row-major order

匿名 (未验证) 提交于 2019-12-03 03:04:01

问题:

I have an array of doubles, and I want to create a 4-by-4 matrix using the Eigen library. I also want to specify that the data is stored in row-major order. How can I do this?

I have tried the following, but it does not compile:

double data[16]; Eigen::Matrix4d M = Eigen::Map<Eigen::Matrix4d>(data, 4, 4, Eigen::RowMajor); 

回答1:

You need to pass a row-major matrix type to Map, e.g.:

Map<Matrix<double,4,4,RowMajor> > M(data); 

then you can use M as an Eigen matrix, and the values of data will be modified, e.g.:

M = M.inverse(); 

If you want to copy the data to a true column-major Eigen matrix, then do:

Matrix4d M = Map<Matrix<double,4,4,RowMajor> >(data); 

Of course, you can also copy to a row-major matrix by using the right type for M.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!