svd3x3.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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_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. // BEWARE: this SVD algorithm guarantees that det(U) = det(V) = 1, but this
  17. // comes at the cost that 'sigma3' can be negative
  18. // for computing polar decomposition it's great because all we need to do is U*V'
  19. // and the result will automatically have positive determinant
  20. //
  21. // Inputs:
  22. // A 3x3 matrix
  23. // Outputs:
  24. // U 3x3 left singular vectors
  25. // S 3x1 singular values
  26. // V 3x3 right singular vectors
  27. //
  28. // Known bugs: this will not work correctly for double precision.
  29. template<typename T>
  30. IGL_INLINE void svd3x3(
  31. const Eigen::Matrix<T, 3, 3>& A,
  32. Eigen::Matrix<T, 3, 3> &U,
  33. Eigen::Matrix<T, 3, 1> &S,
  34. Eigen::Matrix<T, 3, 3>&V);
  35. }
  36. #ifndef IGL_STATIC_LIBRARY
  37. # include "svd3x3.cpp"
  38. #endif
  39. #endif