# Quaternions discontinuities

It is claimed in this paper: https://openaccess.thecvf.com/content_CVPR_2019/papers/Zhou_On_the_Continuity_of_Rotation_Representations_in_Neural_Networks_CVPR_2019_paper.pdf (page 5748)

that the mapping from mapping from rotations to quaternions is discontinuous at 180 degrees.

It doesn't seem true.

Rotation of 3.1 radians around z-axis:

Matrix

[ -0.9991351, -0.0415807, 0.0000000;

0.0415807, -0.9991351, 0.0000000;

0.0000000, 0.0000000, 1.0000000 ]

Quaternion

[ 0, 0, 0.9997838, 0.0207948 ]

Rotation of 3.3 radians around z-axis:

[ -0.9874797, 0.1577457, 0.0000000;

-0.1577457, -0.9874797, 0.0000000;

0.0000000, 0.0000000, 1.0000000 ]

Quaternion:

[ 0, 0, 0.996865, -0.0791209 ]

As we can see, the quaternion representation barely changed. I would hardly call this discontinuous.

• This is not a proof or disproof of continuity. Simply checking one case proves nothing. Dec 8, 2020 at 12:21
• Maybe they refer to "gimbal lock" ... en.wikipedia.org/wiki/Gimbal_lock Dec 8, 2020 at 12:22
• @MattSamuel We would expect to see the behavior at 180 degree. See the paper. thats exactly what they say Dec 8, 2020 at 12:24
• This is definitely gimble lock and it's the main motivation for using quaternions for rotational computations over traditional linear methods. This can have significant real-world consequences if you're say, designing a fly-by-wire system for aircraft. You don't want the plane suddenly flipping upside down. Sep 17, 2022 at 23:07

When determining quaternions from a rotation matrix, there is a nonuniqueness as 2 sets of quaternions can be determined for any general rotation matrix. A common means of dealing with this problem is to ensure that one of the quaterion components is always positive. While this guarantees a unique solution acceptable for many applications, it forces a discontinuous sign change in other components.

In this case, if you always wanted to keep your 4th term positive, the quaternion for the rotation of 3.1 radians will be same which is

[ 0, 0, 0.9997838, 0.0207948 ] (1)

However when you talk about 3.3 radians and talking about unique quaternioins, to get the 4th term positive you'll have to multiply the entire quaternion by -1, i.e

-[0, 0, 0.996865, -0.0791209]

Which is equal to [0, 0, -0.99685, 0.079] (2)

Comparing quaternion (1) and quaternion (2) you can see a jump in the sign and hence the discontinuity at pi radians.

I think I know what you're getting at, but let me know if I get it wrong (assuming you're still invested in an explanation!).

I don't know which specific mapping the paper chose. It's possible they chose the mapping in which each rotation gets mapped to the appropriate quaternion with a positive scalar (real) component. In that case, the second quaternion would be $$0.079121-0.996865\mathbf{k}$$, which is (as advertised) far off from the corresponding quaternion at $$3.1$$ radians.

The underlying issue is that the quaternions are a double cover of $$SO(3)$$, and for the mapping from $$SO(3)$$ to $$\mathbb{H}^*$$, you have to choose which quaternion goes to each rotation. No matter what choices you make, you will end up with a neighborhood of rotations somewhere that has widely divergent quaternions.

A similar thing happens if you try to define a square root function on the complex plane. Here, again, you have two choices for $$\sqrt{z}$$ if $$w^2 = z$$: $$w$$ and $$-w$$. If you were to choose whichever one has positive real component (by analogy with what we just did with the quaternions), you end up with a discontinuity at $$z = -1$$, no matter whether you pick $$i$$ or $$-i$$.

Nor can you avoid the problem by making other choices. Imagine traversing the unit circle counterclockwise from $$1$$, back to $$1$$. Whatever choice you make for your square root, traverses the same circle in the same direction, but at half the speed. So suppose you choose $$\sqrt{1} = 1$$ (sensibly). Then you have

$$\sqrt{i} = \frac{\sqrt{2}}{2} + \frac{\sqrt{2}}{2}i$$ $$\sqrt{-1} = i$$ $$\sqrt{-i} = -\frac{\sqrt{2}}{2} + \frac{\sqrt{2}}{2}i$$

and lastly, $$\sqrt{1} = -1$$. Oops. We've made $$z$$ make a full turn around the origin, but its square root has only made a half turn.

Nor can you even fix this by making the square root multi-valued, because now you have to decide which value comes "first." The best you can say is that both values are valid square roots, but you can't make square root a continuous function.

Anyway, we can make the same problem happen in the quaternions by looking at the mapping of rotations of $$\theta$$ around the $$z$$-axis, all the way from $$\theta = 0$$ to $$\theta = 2\pi$$. Whatever you do, you either have a discontinuity somewhere along the way, or else you end up swapping $$1$$ for $$-1$$.