In 3D space, I have an angle theta representing the orientation of the object. This angle is the result of the atan2 function. Using theta, how can I derive the unit quaternion which represents the object's orientation? You can also assume it is happening in 2D space if not possible in 3D.
Asked
Active
Viewed 127 times
-2
-
1To specify an orientation in 3D you need at least four parameters. How are you expecting to do it with one? – rschwieb Feb 21 '22 at 19:53
1 Answers
1
In 3D is not possible. Let's say that $\theta$ is the angle with respect to $z$ axis. The locus of the points at angle $\theta$ with respect to $z$ is a cone. Then a quaternion rotation of the $z$ axis will yield a "generatrix", but you have an infinite number of them.
It is possible in the plane. If $\theta$ is the angle from the $x$ axis towards $y$, then the axis of rotation is $\hat z$, with the rotation angle $\theta$, so $$\mathbf q=\cos\frac\theta2+\hat i 0+\hat j0+\hat k\sin\frac\theta2$$
Andrei
- 37,370
-
1Thanks! It looks like I was able to use that formula to fix my code. – Ahmet Soyyiğit Feb 21 '22 at 19:26
-
One more thing, how can I do the inverse? Given a quaternion, how do I calculate the atan2? – Ahmet Soyyiğit Feb 22 '22 at 21:39
-
Just by definition, a unit quaternion is $\cos\frac\theta2+(u_x\hat i+u_i\hat j+u_z\hat k)\sin\frac\theta2$. $(u_x,u_y,u_z)$ is the rotation axis. The final formula is easy to calculate – Andrei Feb 22 '22 at 22:31