polar_svd.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #ifndef IGL_POLAR_SVD
  9. #define IGL_POLAR_SVD
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. // Computes the polar decomposition (R,T) of a matrix A using SVD singular value decomposition
  15. // Inputs:
  16. // A 3 by 3 matrix to be decomposed
  17. // Outputs:
  18. // R 3 by 3 rotation matrix part of decomposition
  19. // T 3 by 3 stretch matrix part of decomposition
  20. // U 3 by 3 left-singular vectors
  21. // S 3 by 1 singular values
  22. // V 3 by 3 right-singular vectors
  23. //
  24. // Example:
  25. // polar_svd(A,R,T,U,S,V);
  26. // // Check if R is a reflection
  27. // if(R.determinant() < ))
  28. // {
  29. // // flip last column of U and rebuild to get rotation
  30. // U.col(U.cols()-1) *= -1.0;
  31. // R = U * V.transpose();
  32. // }
  33. //
  34. template <
  35. typename DerivedA,
  36. typename DerivedR,
  37. typename DerivedT,
  38. typename DerivedU,
  39. typename DerivedS,
  40. typename DerivedV>
  41. IGL_INLINE void polar_svd(
  42. const Eigen::PlainObjectBase<DerivedA> & A,
  43. Eigen::PlainObjectBase<DerivedR> & R,
  44. Eigen::PlainObjectBase<DerivedT> & T,
  45. Eigen::PlainObjectBase<DerivedU> & U,
  46. Eigen::PlainObjectBase<DerivedS> & S,
  47. Eigen::PlainObjectBase<DerivedV> & V);
  48. template <
  49. typename DerivedA,
  50. typename DerivedR,
  51. typename DerivedT>
  52. IGL_INLINE void polar_svd(
  53. const Eigen::PlainObjectBase<DerivedA> & A,
  54. Eigen::PlainObjectBase<DerivedR> & R,
  55. Eigen::PlainObjectBase<DerivedT> & T);
  56. }
  57. #ifdef IGL_HEADER_ONLY
  58. # include "polar_svd.cpp"
  59. #endif
  60. #endif