我正在尝试对 Eigen 的 Matrix<int,200,200>
进行简单的转换, 但我无法获得 Eigen::Translation
上类。由于我是 C++ 的新手,Eigen 的官方文档对我来说用处不大。我无法从中提取任何有用的信息。我试图将我的翻译声明为:
Translation<int,2> t(1,0);
希望进行简单的一行移位,但我无法让它对我的矩阵做任何事情。实际上,我什至不确定这是否是该方法的用途……如果不是,您能否推荐一些其他的,最好是快速的,在圆环上进行矩阵转换的方法?我正在寻找与 MATLab 的 circshift 等效的方法。
最佳答案
Translation
类模板来自 Geometry 模块,表示平移转换。它与数组/矩阵中的值移动无关。
根据 this discussion ,到 2010 年为止,转换功能尚未实现,并且当时的优先级较低。 4 年后,我在文档中没有看到任何迹象表明现在情况有任何不同。
所以,你需要自己动手。例如:
/// Shifts a matrix/vector row-wise.
/// A negative \a down value is taken to mean shifting up.
/// When passed zero for \a down, the input matrix is returned unchanged.
/// The type \a M can be either a fixed- or dynamically-sized matrix.
template <typename M> M shiftedByRows(const M & in, int down)
{
if (!down) return in;
M out(in.rows(), in.cols());
if (down > 0) down = down % in.rows();
else down = in.rows() - (-down % in.rows());
// We avoid the implementation-defined sign of modulus with negative arg.
int rest = in.rows() - down;
out.topRows(down) = in.bottomRows(down);
out.bottomRows(rest) = in.topRows(rest);
return out;
}
关于c++ - 如何移动 Eigen 中的矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25218111/