bug #824: improve accuracy of Quaternion::angularDistance using atan2 instead of acos.

(grafted from 2dc968e453e347966b7a45c9c497c6b1d3845f80
)
This commit is contained in:
Gael Guennebaud 2015-03-04 17:03:13 +01:00
parent 500c36de61
commit 88c844ae2f

View File

@ -667,12 +667,10 @@ template <class OtherDerived>
inline typename internal::traits<Derived>::Scalar inline typename internal::traits<Derived>::Scalar
QuaternionBase<Derived>::angularDistance(const QuaternionBase<OtherDerived>& other) const QuaternionBase<Derived>::angularDistance(const QuaternionBase<OtherDerived>& other) const
{ {
using std::acos; using std::atan2;
using std::abs; using std::abs;
Scalar d = abs(this->dot(other)); Quaternion<Scalar> d = (*this) * other.conjugate();
if (d>=Scalar(1)) return Scalar(2) * atan2( d.vec().norm(), abs(d.w()) );
return Scalar(0);
return Scalar(2) * acos(d);
} }