5

I have seen different people saying different things about this so I'm confused. Assuming that each element of the Quaternion vector represents a rotation along some axis, it does not make sense to be able to rotate something more than $\pm360^\circ$. Based on this intuition, we can normalize all elements of this 4-D vector to get values in the range $[-1, 1]$.

Although I might be wrong in my intuition/interpretation, some other people say that the $L_2$ Norm of the 4-D Quaternion vector must not exceed more than $1$. However, if all values of the Quaternion vector are $\pm1$ the $L_2$ Norm would be $2$. So I am confused on what is the range of valid values for the elements of a Quaternion vector. More specifically, what would be the valid range of values for the elements of the Quaternion vector if I want to limit the rotation in a 3D (XYZ) space to, say, $\pm30^\circ$ or $\pm45^\circ$ along each axis? I would appreciate if someone can clarify on this.

The reason that I need to know the valid ranges for the Quaternion vector elements is that I want to avoid using Euler angles to rotate 3D shapes. Instead, I want to be able to randomly sample valid Quaternion vectors. So I need to know what to set the maximum and minimum value of each of the elements so that I get a valid Quaternion rotation. Also, I need to set these bounds in an optimization algorithm.

Amir
  • 475

1 Answers1

4

Any nonzero quaternion you like will give you a rotation; it doesn't matter how big or small its coefficients are. This is because quaternions act on vectors by conjugation: that is, the rotation of a vector $v$ by a quaternion $q$ is a the vector $qvq^{-1}$ (where we think of vectors as being imaginary quaternions). So if $r$ is any scalar (real number), then the rotation of $v$ by the quaternion $rq$ will be $$(rq)v(rq)^{-1}=rqv\frac{q^{-1}}{r}=qvq^{-1}$$ That is, scaling $q$ is irrelevant because $q^{-1}$ will scale inversely.

So if all you want to do is give some quaternion and have it specify a rotation, then any invertible quaternion will do. In your case, however, you want to find a random rotation using quaternions. If you do this by allowing all your coefficients to vary over $[-1,1]$, you will find that your random rotation is biased. Rotations near $\pm 1\pm i\pm j\pm k$ will occur more frequently than rotations near $\pm 1$, $\pm i$, $\pm j$, or $\pm k$, because there are more possible scalings of them in your range.

If you want to generate a uniformly random set of quaternions, you can get around this by rejection sampling: allow your coefficients to vary over $[-1,1]$, but then throw out any quaternion which has norm greater than $1$ and start over. This will cancel out the bias from the previous paragraph. Probably whoever told you that the $L_2$ norm shouldn't exceed $1$ was talking about doing something like this.

If you additionally want to ensure that the Euler angles don't exceed some specified value, that probably means more rejection sampling. The set of quaternions whose Euler angles are all small doesn't have a particularly nice description, but you can generate a random quaternion, find the corresponding Euler angles via these formulae, and throw out the quaternion if they're not small enough.

(If your Euler angle threshold is really small, this becomes inefficient and you should look for an approximate solution instead, but if it's 30˚ or 45˚, the rejection sampling approach should work fine...)

Micah
  • 38,733
  • This is all great but one of my problems is still unsolved unfortunately although I think I got some intuitions from you on how to solve it empirically. Basically, I also need to know the valid range of values for the elements of the Quaternion vector to set up my optimization algorithm's bounds on the variables x, y, z and w. – Amir Oct 31 '18 at 19:54
  • Based on your response it looks like it is not possible to deterministically calculate these bounds. Therefore, I have to keep sampling and keep converting Quaternions to Euler and keep the ones that are within the range of my interest. Then I get the max() and min() values of the remaining vectors. These could be my bounds. But this could be pretty inefficient. I wonder if there are more efficient ways of doing this? I would ideally want to compute these bounds in a deterministic manner ... . Would that be a possibility? – Amir Oct 31 '18 at 19:55
  • The problem is, the bounds for your different coefficients are going to depend on each other in possibly complicated ways. So you'll never get a perfect set of bounds; there's always going to be some rejection involved. And figuring out a better set of bounds involves working out the geometry of some complicated four-dimensional object. You could do it if you really wanted, but it'd be a lot of trouble, and random numbers are cheap. – Micah Oct 31 '18 at 20:24
  • 1
    If you're going to do your max/min approach to find bounds, I'd recommend that you: 1) throw out quaternions with small $L_2$ norms (say, less than $\frac{1}{2}$) as well as large ones, as otherwise your bounds won't be useful, and 2) generate a really huge number of quaternions to find your bounds (leave your computer on overnight), as otherwise you might miss some low-probability part of the region. I would only do this if you had a lot more computing time for optimization than you wanted to spend actually running your program (say, because this is going to be client-side Javascript). – Micah Oct 31 '18 at 20:29
  • One more thought: part of what makes this hard is that Euler angles are kind of unnatural; they privilege the three coordinate axes over other rotations. If that unnaturalness is part of the structure of your problem, then you'll just have to live with that. But if your ultimate goal is just "produce a random small rotation" and the definition of "small" has some flexibility, you'll get a simpler answer if you try to bound, say, the angle in the axis-angle representation of your rotation. – Micah Oct 31 '18 at 20:44
  • I have a new, relevant question here. Could you please take a look at it and see if you can provide an answer? – Amir Nov 09 '18 at 22:45
  • @Micah Your answer here solved OP's XY problem, but I am curious - what are the actual valid ranges for Quaternion elements? – Aaron Franke Mar 28 '20 at 01:19
  • @AaronFranke Valid for what purpose? Any nonzero quaternion gives you a rotation, but generating a random rotation by generating a random quaternion may or may not give you the distribution you're looking for... – Micah Mar 28 '20 at 01:35
  • @Micah Valid as in the Quaternion represents a pure rigid rotation with no scaling, stretching, or dilation. As shown here, there are many such Quaternions: www.youtube.com/watch?v=d4EgbgTm0Bg&t=26m57s I want to verify that the Quaternion doesn't represent something that would stretch around the test sphere in this way. – Aaron Franke Mar 28 '20 at 10:07
  • @AaronFranke: It depends on which space you're acting on! The OP was asking about the quaternion action on $\mathbb{R}^3$, in which case any nonzero quaternion gives a rotation. Your video is talking about quaternion actions on $\mathbb{R}^4$. Multiplying by the quaternion $q$ rotates in some way and also scales by $|q|$, just like multiplying by a complex number $re^{i\theta}$ scales by $r$ and rotates by $\theta$. So only unit quaternions give rotations under this action. – Micah Mar 28 '20 at 13:42