# Expressing unit quaternions in three degrees of freedom

Short version of question: I am trying to use quaternions to avoid gimbal-lock, but I don't know how to express unit quaternions using three degrees of freedom without re-introducing Euler angles and (I suspect) the problem of gimbal-lock.

Long version of question: I confess am not very familiar with the limitations of numberic solvers (such as gradient-descent method) for finding minima of functions. I am concerned that if I feed in extra dependent variables or if I have weird situations that could arise (such as gimbal-lock) the solvers may behave strangely. Which leads to my question: is there a way to express the unit vector part of a unit quaternion with only two variables, other than using spherical coordinates (which essentially re-introduces the gimbal-lock)?

Context of the problem: I am trying to devise a way to reverse-solve the relative position/orientation between two stereo cameras. There are six degrees of freedom here: three translation, three rotation. The basic idea is to pre-calibrate each camera so you can express the direction each pixel points as a vector in the camera's reference frame, where in the pinhole camera model each vector from a single camera passes through a common point in space. Then, you can pick an object (say some corner) that you can see from both cameras. The pixel on that object from the first camera represents a vector from the first camera's position. The second camera also has a pixel on that object, representing a second vector, this time from the second camera's position. These two vectors should intersect, since they point at the same object. Finding several such intersecting vectors between the two cameras will give you enough constraints to solve your six-degrees-of-freedom issue, and finding more-than-enough common points will leave you with a non-linear least-squares sort of problem, which I am trying to solve numerically.

• +1 for the well-written question. I'll assume you have already googled quaternions so I won't suggest that. Clarification, though: you speak of 6 degrees of freedom but shouldn't there be 12, 6 for each camera? – wltrup Aug 12 '15 at 17:57
• Thank you. For simplicity, you can just set one camera's coordinate frame to be your inertial coordinate frame. After the two cameras are calibrated to each other you can worry about the relationship between your stereo camera's coordinate frame and the coordinate frame of the rest of the world. – rexroni Aug 12 '15 at 19:19
• Ah, yes, of course. Heh, one would think that, as a physicist, I should have thought of that right away. I guess I am getting old... – wltrup Aug 12 '15 at 19:43