Browse Source

improved robustness of igl::angles

Former-commit-id: 9a436d54b30a8bfb7cb131e31d64ed2b0ab79920
Daniele Panozzo 10 years ago
parent
commit
f6431e78b9
2 changed files with 6 additions and 2 deletions
  1. 1 1
      build/Makefile.conf
  2. 5 1
      include/igl/angles.cpp

+ 1 - 1
build/Makefile.conf

@@ -107,7 +107,7 @@ endif
 ifeq ($(IGL_USERNAME),daniele)
 	IGL_WITH_MATLAB=0
 	AFLAGS=-m64
-	GG=g++-4.7
+	GG=g++-4.8
 	EIGEN3_INC=-I/usr/local/include/eigen3
 endif
 

+ 5 - 1
include/igl/angles.cpp

@@ -24,7 +24,11 @@ void igl::angles(
     Eigen::RowVector3d v1 = (x-y).normalized();
     Eigen::RowVector3d v2 = (z-y).normalized();
 
-    return acos(v1 * v2.transpose());
+    // http://stackoverflow.com/questions/10133957/signed-angle-between-two-vectors-without-a-reference-plane
+    double s = v1.cross(v2).norm();
+    double c = v1.dot(v2);
+
+    return atan2(s, c);
   };
 
   for(unsigned i=0; i<F.rows(); ++i)