From c8e9cca9123295e2994a3530a1114917aaf4dc8a Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Sun, 26 Nov 2017 12:07:58 +0100 Subject: [PATCH] Compute the inverse quaternion using its conjugate --- src/mathematics/Quaternion.h | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/mathematics/Quaternion.h b/src/mathematics/Quaternion.h index 28f7b636..b8e75306 100644 --- a/src/mathematics/Quaternion.h +++ b/src/mathematics/Quaternion.h @@ -224,16 +224,11 @@ inline void Quaternion::normalize() { // Inverse the quaternion inline void Quaternion::inverse() { - // Get the square length of the quaternion - decimal lengthSquareQuaternion = lengthSquare(); - - assert (lengthSquareQuaternion > MACHINE_EPSILON); - - // Compute and return the inverse quaternion - x /= -lengthSquareQuaternion; - y /= -lengthSquareQuaternion; - z /= -lengthSquareQuaternion; - w /= lengthSquareQuaternion; + // Use the conjugate of the current quaternion + x = -x; + y = -y; + z = -z; + w = w; } // Return the unit quaternion @@ -261,13 +256,8 @@ inline Quaternion Quaternion::getConjugate() const { // Return the inverse of the quaternion (inline) inline Quaternion Quaternion::getInverse() const { - decimal lengthSquareQuaternion = lengthSquare(); - - assert (lengthSquareQuaternion > MACHINE_EPSILON); - - // Compute and return the inverse quaternion - return Quaternion(-x / lengthSquareQuaternion, -y / lengthSquareQuaternion, - -z / lengthSquareQuaternion, w / lengthSquareQuaternion); + // Return the conjugate quaternion + return Quaternion(-x, -y, -z, w); } // Scalar product between two quaternions