added function to prevent quaternion sign jump

This commit is contained in:
Marius Eggert 2024-03-13 16:59:14 +01:00
parent 47b21caf5f
commit 27c8a97d45
2 changed files with 11 additions and 0 deletions

View File

@ -72,6 +72,15 @@ void QuaternionOperations::slerp(const double q1[4], const double q2[4], const d
normalize(q); normalize(q);
} }
void QuaternionOperations::preventSignJump(double qNew[4], const double qOld[4]) {
double qDiff[4] = {0, 0, 0, 0}, qSum[4] = {0, 0, 0, 0};
VectorOperations<double>::subtract(qOld, qNew, qDiff, 4);
VectorOperations<double>::add(qOld, qNew, qSum, 4);
if (VectorOperations<double>::norm(qDiff, 4) > VectorOperations<double>::norm(qSum, 4)) {
VectorOperations<double>::mulScalar(qNew, -1, qNew, 4);
}
}
QuaternionOperations::QuaternionOperations() {} QuaternionOperations::QuaternionOperations() {}
void QuaternionOperations::normalize(const double* quaternion, double* unitQuaternion) { void QuaternionOperations::normalize(const double* quaternion, double* unitQuaternion) {

View File

@ -28,6 +28,8 @@ class QuaternionOperations {
static void rotationFromQuaternions(const double qNew[4], const double qOld[4], static void rotationFromQuaternions(const double qNew[4], const double qOld[4],
const double timeDelta, double rotRate[3]); const double timeDelta, double rotRate[3]);
static void preventSignJump(double qNew[4], const double qOld[4]);
/** /**
* returns angle in ]-Pi;Pi] or [0;Pi] if abs == true * returns angle in ]-Pi;Pi] or [0;Pi] if abs == true
*/ */