From 093f981719a24a25c0aa2a8184c287741b38c615 Mon Sep 17 00:00:00 2001 From: Trung Nguyen Date: Sat, 23 May 2020 23:52:00 -0500 Subject: [PATCH 1/3] Improved the way body inertia moments are checked if they are zero when updating body quaterions in fix rigid/nve --- src/math_extra.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/math_extra.cpp b/src/math_extra.cpp index 797d210d0e..0fe04b6d43 100644 --- a/src/math_extra.cpp +++ b/src/math_extra.cpp @@ -258,8 +258,8 @@ void no_squish_rotate(int k, double *p, double *q, double *inertia, // obtain phi, cosines and sines phi = p[0]*kq[0] + p[1]*kq[1] + p[2]*kq[2] + p[3]*kq[3]; - if (fabs(inertia[k-1]) < 1e-6) phi *= 0.0; - else phi /= 4.0 * inertia[k-1]; + phi /= (4.0 * inertia[k-1]); + if (!std::isfinite(phi)) phi = 0.0; c_phi = cos(dt * phi); s_phi = sin(dt * phi); From bc5c2676303e9027cd68ae56bf7f2718a6414ea8 Mon Sep 17 00:00:00 2001 From: Trung Nguyen Date: Mon, 25 May 2020 23:37:49 -0500 Subject: [PATCH 2/3] Reverted to using a threshold much smaller than 1e-6 for zero inertia moments --- src/math_extra.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/math_extra.cpp b/src/math_extra.cpp index 0fe04b6d43..e600177eb8 100644 --- a/src/math_extra.cpp +++ b/src/math_extra.cpp @@ -258,8 +258,8 @@ void no_squish_rotate(int k, double *p, double *q, double *inertia, // obtain phi, cosines and sines phi = p[0]*kq[0] + p[1]*kq[1] + p[2]*kq[2] + p[3]*kq[3]; - phi /= (4.0 * inertia[k-1]); - if (!std::isfinite(phi)) phi = 0.0; + if (fabs(inertia[k-1]) < 1e-250) phi *= 0.0; + else phi /= 4.0 * inertia[k-1]; c_phi = cos(dt * phi); s_phi = sin(dt * phi); From fac897587ff4fe5ac5a0ca99d10dbe60edcfe699 Mon Sep 17 00:00:00 2001 From: ndtrung Date: Sat, 30 May 2020 07:42:34 -0500 Subject: [PATCH 3/3] Checked for zero inertia moments in a simpler way, similar to what is done in mq_to_omega() --- src/math_extra.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math_extra.cpp b/src/math_extra.cpp index e600177eb8..749736ef27 100644 --- a/src/math_extra.cpp +++ b/src/math_extra.cpp @@ -258,7 +258,7 @@ void no_squish_rotate(int k, double *p, double *q, double *inertia, // obtain phi, cosines and sines phi = p[0]*kq[0] + p[1]*kq[1] + p[2]*kq[2] + p[3]*kq[3]; - if (fabs(inertia[k-1]) < 1e-250) phi *= 0.0; + if (inertia[k-1] == 0.0) phi = 0.0; else phi /= 4.0 * inertia[k-1]; c_phi = cos(dt * phi); s_phi = sin(dt * phi);