Commit 83c3121c14e0f5d78a87ba843a9c5843adfff24b
1 parent
90f83371
NaN value for |AxB| > 1 in some cases
Showing
3 changed files
with
10 additions
and
5 deletions
Show diff stats
stim/biomodels/centerline.h
@@ -25,7 +25,10 @@ protected: | @@ -25,7 +25,10 @@ protected: | ||
25 | if (i == size() - 1) return at(size() - 1) - at(size() - 2); //the last direction vector is oriented towards the last line segment | 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 | //all other direction vectors are the average direction of the two joined line segments | 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<T> a = at(i) - at(i - 1); |
29 | + vec3<T> b = at(i + 1) - at(i); | ||
30 | + vec3<T> ab = a.norm() + b.norm(); | ||
31 | + return ab.norm(); | ||
29 | } | 32 | } |
30 | //initializes the integrated length vector to make parameterization easier, starting with index idx (all previous indices are assumed to be correct) | 33 | //initializes the integrated length vector to make parameterization easier, starting with index idx (all previous indices are assumed to be correct) |
31 | void update_L(size_t start = 0) { | 34 | void update_L(size_t start = 0) { |
stim/math/plane.h
@@ -188,9 +188,9 @@ class plane | @@ -188,9 +188,9 @@ class plane | ||
188 | { | 188 | { |
189 | quaternion<T> q; | 189 | quaternion<T> q; |
190 | q.CreateRotation(N, n); | 190 | q.CreateRotation(N, n); |
191 | - | ||
192 | - N = q.toMatrix3() * N; | ||
193 | - U = q.toMatrix3() * U; | 191 | + matrix_sq<T, 3> 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,7 +46,9 @@ public: | ||
46 | from = from.norm(); | 46 | from = from.norm(); |
47 | to = to.norm(); | 47 | to = to.norm(); |
48 | vec3<T> r = from.cross(to); //compute the rotation vector | 48 | vec3<T> 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 | //deal with a zero vector (both k and kn point in the same direction) | 52 | //deal with a zero vector (both k and kn point in the same direction) |
51 | if(theta == (T)0){ | 53 | if(theta == (T)0){ |
52 | return; | 54 | return; |