From c6e5f6052513b6b1fb07682371ec08a6d4c0584b Mon Sep 17 00:00:00 2001 From: Alexey Shtern Date: Fri, 10 Mar 2023 10:37:43 +0200 Subject: [PATCH] Merge pull request #23301 from shtern:fix_quaternion Fixed strict type in slerp and spline; Fixed nlerp usage condition Fixes #23293 The PR is fixing the issue described in [Issue #23293 ](https://github.com/opencv/opencv/issues/23293) - [X] I agree to contribute to the project under Apache 2 License. - [X] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [X] The PR is proposed to the proper branch - [X] There is a reference to the original bug report and related work - [X] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [X] The feature is well documented and sample code can be built with the project CMake --- modules/core/include/opencv2/core/quaternion.inl.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/core/include/opencv2/core/quaternion.inl.hpp b/modules/core/include/opencv2/core/quaternion.inl.hpp index 29a16d9f7d..b901ecbc68 100644 --- a/modules/core/include/opencv2/core/quaternion.inl.hpp +++ b/modules/core/include/opencv2/core/quaternion.inl.hpp @@ -745,8 +745,8 @@ Quat Quat::lerp(const Quat &q0, const Quat &q1, const T t) template Quat Quat::slerp(const Quat &q0, const Quat &q1, const T t, QuatAssumeType assumeUnit, bool directChange) { - Quatd v0(q0); - Quatd v1(q1); + Quat v0(q0); + Quat v1(q1); if (!assumeUnit) { v0 = v0.normalize(); @@ -754,7 +754,7 @@ Quat Quat::slerp(const Quat &q0, const Quat &q1, const T t, QuatAssu } T cosTheta = v0.dot(v1); constexpr T DOT_THRESHOLD = 0.995; - if (cosTheta > DOT_THRESHOLD) + if (std::abs(cosTheta) > DOT_THRESHOLD) { return nlerp(v0, v1, t, QUAT_ASSUME_UNIT); } @@ -843,7 +843,7 @@ Quat Quat::interPoint(const Quat &q0, const Quat &q1, template Quat Quat::spline(const Quat &q0, const Quat &q1, const Quat &q2, const Quat &q3, const T t, QuatAssumeType assumeUnit) { - Quatd v0(q0), v1(q1), v2(q2), v3(q3); + Quat v0(q0), v1(q1), v2(q2), v3(q3); if (!assumeUnit) { v0 = v0.normalize();