# What is the valid range for elements of a Quaternion vector to be used for rotation?

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.

• Are you using quaternions to specify three-dimensional rotations or four-dimensional rotations? – Micah Oct 31 '18 at 19:09
• @Micah I basically want to avoid using Euler angles. So I guess it should be 3 dimensions? – Amir Oct 31 '18 at 19:10
• @Micah I updated my question a little bit more. Is it more clear now? – Amir Oct 31 '18 at 19:22
• Yeah, thanks. I'm in the middle of writing an answer... – Micah Oct 31 '18 at 19:22

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 allow 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...)

• 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
• 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