polar_svd.h 1.5 KB

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