1、判断两个矩阵是否相等(对应元素之差的绝对值小于一个很小的浮点数)
template<typename Derived>
bool judgeEigenMatrixEqual(const Eigen::MatrixBase<Derived>& mat1, const Eigen::MatrixBase<Derived>& mat2, const double precision = 1e-5)
{
if (mat1.rows() != mat2.rows() || mat1.cols() != mat2.cols()) return false;
return ((mat1.array() - mat2.array()).cwiseAbs().cast<double>().maxCoeff() < precision);
}
//使用
Eigen::MatrixXf mat1, mat2;
bool isEqual = judgeEigenMatrixEqual<Eigen::MatrixXf>(mat1, mat2);
2、Eigen::vector与std::vector的相互转换,std::vector转Eigen::MatrixXd也类似
(参考https://blog.csdn.net/github_39582118/article/details/120309991)