From 88c844ae2f3db7f87cab441e186cbdd2f9c7dcc3 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 4 Mar 2015 17:03:13 +0100 Subject: [PATCH] bug #824: improve accuracy of Quaternion::angularDistance using atan2 instead of acos. (grafted from 2dc968e453e347966b7a45c9c497c6b1d3845f80 ) --- Eigen/src/Geometry/Quaternion.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Eigen/src/Geometry/Quaternion.h b/Eigen/src/Geometry/Quaternion.h index f06653f1c..270059bcd 100644 --- a/Eigen/src/Geometry/Quaternion.h +++ b/Eigen/src/Geometry/Quaternion.h @@ -667,12 +667,10 @@ template inline typename internal::traits::Scalar QuaternionBase::angularDistance(const QuaternionBase& other) const { - using std::acos; + using std::atan2; using std::abs; - Scalar d = abs(this->dot(other)); - if (d>=Scalar(1)) - return Scalar(0); - return Scalar(2) * acos(d); + Quaternion d = (*this) * other.conjugate(); + return Scalar(2) * atan2( d.vec().norm(), abs(d.w()) ); }