null.cpp 792 B

123456789101112131415161718192021
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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 "null.h"
  9. #include "EPS.h"
  10. template <typename DerivedA, typename DerivedN>
  11. IGL_INLINE void igl::null(
  12. const Eigen::PlainObjectBase<DerivedA> & A,
  13. Eigen::PlainObjectBase<DerivedN> & N)
  14. {
  15. using namespace Eigen;
  16. typedef typename DerivedA::Scalar Scalar;
  17. JacobiSVD<MatrixXd> svd(A, ComputeFullV);
  18. svd.setThreshold(A.cols() * svd.singularValues().maxCoeff() * EPS<Scalar>());
  19. N = svd.matrixV().rightCols(A.cols()-svd.rank());
  20. }