Skip to content
Snippets Groups Projects
Commit 5bbd2acc authored by ansgar's avatar ansgar
Browse files

fixed a precision issue with rotmat->quat conversion

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2124 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent b3944657
No related branches found
No related tags found
No related merge requests found
...@@ -184,17 +184,20 @@ Vec3 find_vector_for_BOD(const Vec3& xyz, const Vec3& uvw) ...@@ -184,17 +184,20 @@ Vec3 find_vector_for_BOD(const Vec3& xyz, const Vec3& uvw)
Quat extract_from_rotmat(const Mat3& rot) Quat extract_from_rotmat(const Mat3& rot)
{ {
if ((fabs(rot(0,0) - 1.0) <= std::numeric_limits<Real>::epsilon()) && if ((std::abs(rot(0,0) - Real(1.0)) <= std::numeric_limits<Real>::epsilon()) &&
(fabs(rot(1,1) - 1.0) <= std::numeric_limits<Real>::epsilon()) && (std::abs(rot(1,1) - Real(1.0)) <= std::numeric_limits<Real>::epsilon()) &&
(fabs(rot(2,2) - 1.0) <= std::numeric_limits<Real>::epsilon())) { (std::abs(rot(2,2) - Real(1.0)) <= std::numeric_limits<Real>::epsilon())) {
return Quat(1.0,0.0,0.0,0.0); return Quat(1.0,0.0,0.0,0.0);
} }
Real cos_theta = (rot(0,0)+rot(1,1)+rot(2,2)-1.0)*0.5; Real cos_theta = (rot(0,0)+rot(1,1)+rot(2,2)-Real(1.0))*Real(0.5);
Real stuff = (cos_theta+1.0)*0.5; Real stuff = (cos_theta+Real(1.0))*Real(0.5);
if(stuff<Real(0.0) || stuff>Real(1.0)) {
return Quat(1.0,0.0,0.0,0.0);
}
Real cos_theta_sur_2 = sqrt(stuff); Real cos_theta_sur_2 = sqrt(stuff);
Real sin_theta_sur_2 = sqrt(1.0-stuff); Real sin_theta_sur_2 = sqrt(Real(1.0)-stuff);
Vec3 xyz = find_invariant_vector(rot); Vec3 xyz = find_invariant_vector(rot);
Vec3 uvw = find_orthogonal_vector(xyz); Vec3 uvw = find_orthogonal_vector(xyz);
Vec3 rst = find_vector_for_BOD(xyz,uvw); Vec3 rst = find_vector_for_BOD(xyz,uvw);
...@@ -216,7 +219,7 @@ Quat extract_from_rotmat(const Mat3& rot) ...@@ -216,7 +219,7 @@ Quat extract_from_rotmat(const Mat3& rot)
if(desambiguator >= 1.0) { if(desambiguator >= 1.0) {
q = Quat(0.0, +xyz[0], +xyz[1], +xyz[2]); q = Quat(0.0, +xyz[0], +xyz[1], +xyz[2]);
} else { } else {
q = Quat(0, -xyz[0], -xyz[1], -xyz[2]); q = Quat(0.0, -xyz[0], -xyz[1], -xyz[2]);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment