To rotate about the $z$ axis (yaw) by $\alpha$ you need the following quaternion
$\begin{aligned}q = \begin{bmatrix}\cos(\tfrac{\alpha}{2})\\0\\0\\\sin(\tfrac{\alpha}{2})\end{bmatrix}\end{aligned}\tag{1},$
to rotate about the $x$ (pitch) axis you need
$\begin{aligned}q = \begin{bmatrix}\cos(\tfrac{\alpha}{2})\\0\\ \sin(\tfrac{\alpha}{2})\\0\end{bmatrix}\end{aligned}\tag{2},$
and to rotate about $y$ by $\alpha$ you need
$\begin{aligned}q = \begin{bmatrix}\cos(\tfrac{\alpha}{2})\\\sin(\tfrac{\alpha}{2})\\0\\0\end{bmatrix}\end{aligned}\tag{3}.$
If you have a rotation described by the Euler angles $(\phi, \theta, \psi)$ (in the standard order), then, the corresponding quaternion is
$\begin{aligned}
q = \begin{bmatrix}
\cos \tfrac{\phi}{2} \cos \tfrac{\theta}{2} \cos \tfrac{\psi}{2} + \sin \tfrac{\phi}{2} \sin \tfrac{\theta}{2} \sin \tfrac{\psi}{2} \\
\sin \tfrac{\phi}{2} \cos \tfrac{\theta}{2} \cos \tfrac{\psi}{2} - \cos \tfrac{\phi}{2} \sin \tfrac{\theta}{2} \sin \tfrac{\psi}{2} \\
\cos \tfrac{\phi}{2} \sin \tfrac{\theta}{2} \cos \tfrac{\psi}{2} + \sin \tfrac{\phi}{2} \cos \tfrac{\theta}{2} \sin \tfrac{\psi}{2} \\
\cos \tfrac{\phi}{2} \cos \tfrac{\theta}{2} \sin \tfrac{\psi}{2} - \sin \tfrac{\phi}{2} \sin \tfrac{\theta}{2} \cos \tfrac{\psi}{2}
\end{bmatrix}
\end{aligned}\tag{4}.$
If you are rotating your object about an axis described by the vector $u=(u_x, u_y, u_z)\in\mathbb{R}^3$ and by an angle $\alpha$ about that axis, then
$\begin{aligned}q = \begin{bmatrix}\cos(\tfrac{\alpha}{2})\\\sin(\tfrac{\alpha}{2})u\end{bmatrix}=
\begin{bmatrix}\cos(\tfrac{\alpha}{2})\\\sin(\tfrac{\alpha}{2})u_x\\\sin(\tfrac{\alpha}{2})u_y\\\sin(\tfrac{\alpha}{2})u_z\end{bmatrix}
\end{aligned}
\tag{5}.$
If I understand you correctly, you want to do this:
- For positive $w$, calculate the angle $\Omega=2\cos^{-1}w$.
- If $\Omega>\Omega_\max$, calculate $w_1=\cos(\Omega_\max/2)$; other components are scaled by $k = \sin(\Omega_\max/2)/\sin(\Omega/2)$.
- If $w$ was negative on step 1, multiply the quaternion by $-1$, do the procedure and then multiply back.
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)
$$
Best Answer
If you have a quaternion $a + bi + cj + dk$, the unit quaternion corresponding to it is
$$\frac{a + bi + cj + dk}{\sqrt{a^2 + b^2 + c^2 + d^2}}.$$
Particularly, the norm is $\sqrt{a^2+b^2+c^2+d^2}$.