Authored by David Mayerich
1 parent 90f83371

### NaN value for |AxB| > 1 in some cases

Showing 3 changed files with 10 additions and 5 deletions
stim/biomodels/centerline.h

 ... ... @@ -25,7 +25,10 @@ protected: 25 25 if (i == size() - 1) return at(size() - 1) - at(size() - 2); //the last direction vector is oriented towards the last line segment 26 26 27 27 //all other direction vectors are the average direction of the two joined line segments 28 - return ((at(i) - at(i - 1)).norm() + (at(i + 1) - at(i)).norm()).norm(); 28 + vec3 a = at(i) - at(i - 1); 29 + vec3 b = at(i + 1) - at(i); 30 + vec3 ab = a.norm() + b.norm(); 31 + return ab.norm(); 29 32 } 30 33 //initializes the integrated length vector to make parameterization easier, starting with index idx (all previous indices are assumed to be correct) 31 34 void update_L(size_t start = 0) { ... ...
stim/math/plane.h

 ... ... @@ -188,9 +188,9 @@ class plane 188 188 { 189 189 quaternion q; 190 190 q.CreateRotation(N, n); 191 - 192 - N = q.toMatrix3() * N; 193 - U = q.toMatrix3() * U; 191 + matrix_sq M = q.toMatrix3(); 192 + N = M * N; 193 + U = M * U; 194 194 195 195 } 196 196 ... ...
stim/math/quaternion.h

 ... ... @@ -46,7 +46,9 @@ public: 46 46 from = from.norm(); 47 47 to = to.norm(); 48 48 vec3 r = from.cross(to); //compute the rotation vector 49 - T theta = asin(r.len()); //compute the angle of the rotation about r 49 + T l = r.len(); 50 + if (l > 1) l = 1; //we have seen degenerate cases where |r| > 1 (probably due to loss of precision in the cross product) 51 + T theta = asin(l); //compute the angle of the rotation about r 50 52 //deal with a zero vector (both k and kn point in the same direction) 51 53 if(theta == (T)0){ 52 54 return; ... ...