rotate_vectors.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@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 "rotate_vectors.h"
  9. IGL_INLINE Eigen::MatrixXd igl::rotate_vectors(
  10. const Eigen::MatrixXd& V,
  11. const Eigen::VectorXd& A,
  12. const Eigen::MatrixXd& B1,
  13. const Eigen::MatrixXd& B2)
  14. {
  15. Eigen::MatrixXd RV(V.rows(),V.cols());
  16. for (unsigned i=0; i<V.rows();++i)
  17. {
  18. double norm = V.row(i).norm();
  19. // project onto the tangent plane and convert to angle
  20. double a = atan2(B2.row(i).dot(V.row(i)),B1.row(i).dot(V.row(i)));
  21. // rotate
  22. a += (A.size() == 1) ? A(0) : A(i);
  23. // move it back to global coordinates
  24. RV.row(i) = norm*cos(a) * B1.row(i) + norm*sin(a) * B2.row(i);
  25. }
  26. return RV;
  27. }
  28. #ifdef IGL_STATIC_LIBRARY
  29. // Explicit template instantiation
  30. #endif