فهرست منبع

polar_svd always returns rotation.

Former-commit-id: d84a027f1159d2106d2384a8d1a9f3e18bed07a2
Alec Jacobson 11 سال پیش
والد
کامیت
8ef0b823ea
2فایلهای تغییر یافته به همراه13 افزوده شده و 12 حذف شده
  1. 9 1
      include/igl/polar_svd.cpp
  2. 4 11
      include/igl/polar_svd.h

+ 9 - 1
include/igl/polar_svd.cpp

@@ -7,6 +7,7 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "polar_svd.h"
 #include <Eigen/SVD>
+#include <Eigen/Geometry>
 
 // Adapted from Olga's CGAL mentee's ARAP code
 template <
@@ -47,7 +48,14 @@ IGL_INLINE void igl::polar_svd(
   S = svd.singularValues();
   // TODO: Check for sign and switch here.
   R = U*V.transpose();
-  T = V*S.asDiagonal()*V.adjoint();
+  const auto & SV = S.asDiagonal() * V.adjoint();
+  // Check for reflection
+  if(R.determinant() < 0)
+  {
+    V.col(V.cols()-1) *= -1.;
+    R = U*V.transpose();
+  }
+  T = V*SV;
 }
 
 #ifndef IGL_HEADER_ONLY

+ 4 - 11
include/igl/polar_svd.h

@@ -12,25 +12,18 @@
 
 namespace igl
 {
-  // Computes the polar decomposition (R,T) of a matrix A using SVD singular value decomposition
+  // Computes the polar decomposition (R,T) of a matrix A using SVD singular
+  // value decomposition
+  //
   // Inputs:
   //   A  3 by 3 matrix to be decomposed
   // Outputs:
-  //   R  3 by 3 rotation matrix part of decomposition
+  //   R  3 by 3 rotation matrix part of decomposition (**always rotataion**)
   //   T  3 by 3 stretch matrix part of decomposition
   //   U  3 by 3 left-singular vectors
   //   S  3 by 1 singular values
   //   V  3 by 3 right-singular vectors
   //
-  // Example:
-  //   polar_svd(A,R,T,U,S,V);
-  //   // Check if R is a reflection
-  //   if(R.determinant() < ))
-  //   {
-  //     // flip last column of U and rebuild to get rotation
-  //     U.col(U.cols()-1) *= -1.0;
-  //     R = U * V.transpose();
-  //   }
   //
   template <
     typename DerivedA,