svd3x3.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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_SVD3X3_H
  9. #define IGL_SVD3X3_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. namespace igl
  13. {
  14. /// Super fast 3x3 SVD according to http://pages.cs.wisc.edu/~sifakis/project_pages/svd.html
  15. /// The resulting decomposition is A = U * diag(S[0], S[1], S[2]) * V'
  16. ///
  17. /// \note this SVD algorithm guarantees that det(U) = det(V) = 1, but this
  18. /// comes at the cost that 'sigma3' can be negative
  19. /// for computing polar decomposition it's great because all we need to do is U*V'
  20. /// and the result will automatically have positive determinant
  21. ///
  22. /// @param[in] A 3x3 matrix
  23. /// @param[out] U 3x3 left singular vectors
  24. /// @param[out] S 3x1 singular values
  25. /// @param[out] V 3x3 right singular vectors
  26. ///
  27. /// \bug this will not work correctly for double precision.
  28. template<typename T>
  29. IGL_INLINE void svd3x3(
  30. const Eigen::Matrix<T, 3, 3>& A,
  31. Eigen::Matrix<T, 3, 3> &U,
  32. Eigen::Matrix<T, 3, 1> &S,
  33. Eigen::Matrix<T, 3, 3>&V);
  34. }
  35. #ifndef IGL_STATIC_LIBRARY
  36. # include "svd3x3.cpp"
  37. #endif
  38. #endif