orth.cpp 981 B

1234567891011121314151617181920212223242526272829303132
  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. #include "orth.h"
  9. // Broken Implementation
  10. IGL_INLINE void igl::orth(const Eigen::MatrixXd &A, Eigen::MatrixXd &Q)
  11. {
  12. //perform svd on A = U*S*V' (V is not computed and only the thin U is computed)
  13. Eigen::JacobiSVD<Eigen::MatrixXd> svd(A, Eigen::ComputeThinU );
  14. Eigen::MatrixXd U = svd.matrixU();
  15. const Eigen::VectorXd S = svd.singularValues();
  16. //get rank of A
  17. int m = A.rows();
  18. int n = A.cols();
  19. double tol = std::max(m,n) * S.maxCoeff() * 2.2204e-16;
  20. int r = 0;
  21. for (int i = 0; i < S.rows(); ++r,++i)
  22. {
  23. if (S[i] < tol)
  24. break;
  25. }
  26. //keep r first columns of U
  27. Q = U.block(0,0,U.rows(),r);
  28. }