从行优先顺序的数组创建本征矩阵 [英] Creating an Eigen matrix from an array with row-major order

查看:82
本文介绍了从行优先顺序的数组创建本征矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个双精度数组,我想使用Eigen库创建一个4×4矩阵.我还想指定数据以行优先顺序存储.我该怎么办?

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);

推荐答案

您需要将行主要矩阵类型传递给Map,例如:

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

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

然后您可以将M用作特征矩阵,数据值将被修改,例如:

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);

当然,您也可以使用M的正确类型将其复制到以行为主的矩阵.

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

这篇关于从行优先顺序的数组创建本征矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆