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.

Thanks for reading.

  • $\begingroup$ +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? $\endgroup$ – wltrup Aug 12 '15 at 17:57
  • $\begingroup$ 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. $\endgroup$ – rexroni Aug 12 '15 at 19:19
  • $\begingroup$ 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... $\endgroup$ – wltrup Aug 12 '15 at 19:43

To contribute a preliminary answer the first part of your question.

Every representation of rotation with three numbers has issues and contains singularities.

Perhaps the most accessible such representation is the imaginary part of the quaternion, which corresponds to sin(angle/2) times the rotation axis. Its worst discontinuity occurs when the angle is pi or -pi - nothing a generic solver can deal with. This is the problem that the extra number in the quaternion helps fix for numerical solvers.

The rotation vector (rotation axis times angle) is also a good candidate and kind-of solves the above-mentioned problem, but each vector is the same as infinite other vectors (add N*2*pi). You can probably get around that with some carefulness, but solvers that are very efficient take big steps and can cause a problem (choice of solver also important). Also, it still has a singularity at no-rotation (the quaternion solves this by introducing a 4th axis corresponding to "no-rotation") around which you may have numerical issues (imagine the path the solver might need to take from (pi,0,0) to (-pi,0,0)).

My approach would be to use the quaternion with the numerical solver but always normalise - that is, all cost gradients etc. should be with respect to the normalised quaternion.

I hope that helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.