#include#include using Eigen::MatrixXd; int main() { MatrixXd matrix(2,3); matrix << 1, 2, 3, 4, 5, 6; Vector2d translation(1, 2); matrix.rowwise() += translation.transpose(); std::cout << matrix << std::endl; return 0; }
#includeIn this example, we use the MatrixXd::colwise() function to apply column-wise translation to our matrix. We pass in our translation vector and the matrix is translated by (1,2). The code examples here use the Eigen C++ library that provides various matrix and linear algebra operations.#include using Eigen::MatrixXd; int main() { MatrixXd matrix(2,3); matrix << 1, 2, 3, 4, 5, 6; Vector2d translation(1, 2); matrix.colwise() += translation; std::cout << matrix << std::endl; return 0; }