fit_rigid.cpp 838 B

12345678910111213141516171819202122232425
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "fit_rigid.h"
  9. #include "polar_svd.h"
  10. IGL_INLINE void igl::fit_rigid(
  11. const Eigen::MatrixXd & A,
  12. const Eigen::MatrixXd & B,
  13. Eigen::Rotation2Dd & R,
  14. Eigen::RowVector2d & t)
  15. {
  16. // build covariance matrix
  17. const auto & Amean = A.colwise().mean();
  18. const auto & Bmean = B.colwise().mean();
  19. const auto & S = (B.rowwise() - Bmean).transpose() * (A.rowwise() - Amean);
  20. Eigen::Matrix2d Rm,Tm;
  21. polar_svd(S.eval(),Rm,Tm);
  22. R.fromRotationMatrix(Rm);
  23. t = Amean - Bmean*Rm;
  24. }