]> git.scottworley.com Git - nt3d/blobdiff - nt3d.js
Increase the skip-rotation epsilon
[nt3d] / nt3d.js
diff --git a/nt3d.js b/nt3d.js
index 3ce05be192449917990be333d3a0b8a6621b6c17..7198e22cf2482d9e8f8ef4029b8b967f2698a599 100644 (file)
--- a/nt3d.js
+++ b/nt3d.js
@@ -259,7 +259,14 @@ nt3d = {
                        point[2] + offset[2]];
        },
        angle_between: function(a, b) { // a and b must be unit vectors
-               return Math.acos(this.dot(a, b));
+               var the_dot = this.dot(a, b);
+               if (the_dot <= -1) {
+                       return Math.PI;
+               }
+               if (the_dot >= 1) {
+                       return 0;
+               }
+               return Math.acos(the_dot);
        },
        rotate_about_origin: function(points, axis, angle) { // axis must be a unit vector
                // From http://inside.mines.edu/~gmurray/ArbitraryAxisRotation/
@@ -281,8 +288,8 @@ nt3d = {
                // by crossing a and b to get a rotation axis and using
                // angle_between to get a rotation angle.
                var angle = this.angle_between(this.unit(a), this.unit(b));
-               if (Math.abs(angle) < 1e-15) {
-                       // No siginificant rotation to perform.  Bail to avoid
+               if (Math.abs(angle) < 1e-7) {
+                       // No significant rotation to perform.  Bail to avoid
                        // NaNs and numerical error
                        return points;
                }
@@ -353,7 +360,7 @@ nt3d = {
                        if (nan_in_face) nan_face_count ++;
                }
                if (nan_count != 0) {
-                       alert(nan_count + " NaNs in " + nan_point_count + " points in " + nan_face_count + " faces.");
+                       alert(nan_count + " NaNs in " + nan_point_count + " points in " + nan_face_count + " faces (" + (100 * nan_face_count / (this.points.length/3)) + "% of faces).");
                }
 
                // Remove degenerate faces