I have a problem with quaternions used for rotations.
I want to take arbitrary unit quaternions and scale them down if they exceed my goal max rotation.
So assume I get some unit quaternion $q = [w, x, y, z]$, now to check the rotation "magnitude" I can get the angle of rotation from $w$ like so:
$\Omega = 2*\cos^{-1}(w)$, cool.
So now I can check whether this angle is larger than my $\Omega_{\max}$. If that is the case, I want to scale down my $q$. And from $\Omega_{\max}$ I calculate my $w_{\max} = \cos(\frac 12 \Omega_{\max})$.
Basically what I want is to increase (absolutely speaking*) the $w$ amount so that for my $q_{scaled}$ the $w$ fullfills the following condition: $|w_{\text{scaled}}| \geq w_{\max}$.
So of course I know about SLERP and I tried using it for my example.
My idea was: use the start quaternion as my initial too big $q$ and use the 0 rotation quaternion $(1, 0, 0, 0)$ as a goal if my initial $w$ is positive and the 0 quaternion $(-1, 0, 0, 0)$ if my initial $w < 0$.
So that any intermediate quaternion fulfills my two requirements:
- it should keep the same rotation axis and direction
- the rotation "amount" should decrease
And then just find a step in-between these two rotation where
$|w_{\text{intermediate}}| \geq w_{\max}$.
Okay, now my problem is, how do I find that step $t$ for which $SLERP(q, q_{0}, t)$ would fulfill the above requirement?
I tried solving the equation for $w_{\max}$ but it did not yield a satisfying result (those transcendental equation are not easy to solve) . What I can do however and what works, is sample the SLERP function and just stop at a point where the $w$ fits my requirement, but this is also a very ugly solution.
If any of you math cracks can help me out, that would be much appreciated. I did a lot of researching but could not find a suitable solution. I hope I made my problem clear and mathy enough, I am not a mathematician so please be gentle.
* If my $w$ is negative, than I want to decrease my value further since at $w = -1$, the rotation is 0. But if my $w$ value is positive, I want to increase my $w$ because the rotation is also 0 for $w = 1$.
Best Answer
If I understand you correctly, you want to do this:
P.S. Using SLERP with $q_0=1$ is basically the same: $$ Q(t) = q^t = \cos t\Omega+\mathbf v\sin t\Omega,\\ t=\min\left(1, \Omega_\max/\Omega\right) $$