0
我有一個矩陣(x,y,z每列),只想執行二維變換到x和y軸,忽略z。似乎affine2d不能與塊相乘,是否有任何其他方式使其工作?如何將affine2d變換應用到3d矩陣塊上?
Eigen::matrix<double, 3, 4> x3d;
x3d <<
1, 2, 3, 4,
2, 3, 4, 5,
1, 1, 1, 1;
auto x2d = x3d.topRows(2);
Eigen::Affine2d T = Eigen::Translation2d(1, 2) * Eigen::Scaling(1., 2.);
x2d = T*x2d;
輸出錯誤:
> /home/lei/Work/SurfTomo/./include/Eigen/src/Geometry/Transform.h:1361:5:
> error: static_assert failed "YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES"
> EIGEN_STATIC_ASSERT(OtherRows==Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
> ^ ~~~~~~~~~~~~~~ /home/lei/Work/SurfTomo/./include/Eigen/src/Core/util/StaticAssert.h:32:40:
> note: expanded from macro 'EIGEN_STATIC_ASSERT'
> #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
> ^ ~ /home/lei/Work/SurfTomo/./include/Eigen/src/Geometry/Transform.h:442:77:
> note: in instantiation of member function
> 'Eigen::internal::transform_right_product_impl<Eigen::Transform<double,
> 2, 2, 0>, Eigen::Block<Eigen::Matrix<double, 3, 4, 0, 3, 4>, -1, 4,
> false>, 2, 4>::run' requested here { return internal::transform_right_product_impl<Transform,
> OtherDerived>::run(*this,other.derived()); }
> ^/home/lei/Work/SurfTomo/test/test_3dto2d.cc:27:10: note: in
> instantiation of function template specialization
> 'Eigen::Transform<double, 2, 2,
> 0>::operator*<Eigen::Block<Eigen::Matrix<double, 3, 4, 0, 3, 4>, -1, 4, false> >' requested here x2d = T*x2d;
> ^1 error generated.
我發現下面的代碼就可以解決這個問題,但我不明白爲什麼它的工作原理。
x2d = T * x2d.colwise().homogeneous();
謝謝您
x2d
矩陣。優秀的解釋。 – Aristotle0