Compute the inverse quaternion using its conjugate
This commit is contained in:
parent
fea467f112
commit
c8e9cca912
|
@ -224,16 +224,11 @@ inline void Quaternion::normalize() {
|
||||||
// Inverse the quaternion
|
// Inverse the quaternion
|
||||||
inline void Quaternion::inverse() {
|
inline void Quaternion::inverse() {
|
||||||
|
|
||||||
// Get the square length of the quaternion
|
// Use the conjugate of the current quaternion
|
||||||
decimal lengthSquareQuaternion = lengthSquare();
|
x = -x;
|
||||||
|
y = -y;
|
||||||
assert (lengthSquareQuaternion > MACHINE_EPSILON);
|
z = -z;
|
||||||
|
w = w;
|
||||||
// Compute and return the inverse quaternion
|
|
||||||
x /= -lengthSquareQuaternion;
|
|
||||||
y /= -lengthSquareQuaternion;
|
|
||||||
z /= -lengthSquareQuaternion;
|
|
||||||
w /= lengthSquareQuaternion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the unit quaternion
|
// Return the unit quaternion
|
||||||
|
@ -261,13 +256,8 @@ inline Quaternion Quaternion::getConjugate() const {
|
||||||
// Return the inverse of the quaternion (inline)
|
// Return the inverse of the quaternion (inline)
|
||||||
inline Quaternion Quaternion::getInverse() const {
|
inline Quaternion Quaternion::getInverse() const {
|
||||||
|
|
||||||
decimal lengthSquareQuaternion = lengthSquare();
|
// Return the conjugate quaternion
|
||||||
|
return Quaternion(-x, -y, -z, w);
|
||||||
assert (lengthSquareQuaternion > MACHINE_EPSILON);
|
|
||||||
|
|
||||||
// Compute and return the inverse quaternion
|
|
||||||
return Quaternion(-x / lengthSquareQuaternion, -y / lengthSquareQuaternion,
|
|
||||||
-z / lengthSquareQuaternion, w / lengthSquareQuaternion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scalar product between two quaternions
|
// Scalar product between two quaternions
|
||||||
|
|
Loading…
Reference in New Issue
Block a user